• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How to read an Http POST request in Eclipse?

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some java code that generates an Http POST request (org.apache.http.client.methods.HttpPost).

I want to read the exact POST request it is generating (header and body) when debugging it in Eclipse.

It is an api, not a web app.

How to do that?

Thanks.
 
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eclipse is a program to create, edit, and debug programs. It's not intended to act as an application itself.

The only real way to test an HTTP service request is with an HTTP app. That is, a webapp. Eclipse can run a webapp server and debug the webapp logic.

Or, alternatively, you can use a unit test framework that mocks up the functions of a webapp and HTTP transport. Eclipse can run test frameworks as independent Java apps.
 
Jf Okeeffe
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for the answer.

In terms of testing the api I do have an webapp that I'm using for that(postman).

But what I need here is not so much to test it, but to read the HTTP POST request header and body content.

If Eclipse doesn't provide that as a tool, wouldn't be an alternative such as a method from the org.apache.http.client.methods.HttpPost class that returns that info?
 
Tim Holloway
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a couple of options.

1. You can have Eclipse set a breakpoint on the doPost() method of your webapp and examine the variables there. It's definitive, since that's the same data that the live app sees.

2. If you can send the request from a web browser like Firefox that allows detailed network data analysis, you can see the data as it goes out.

3. You can probably use one of the command-line clients such as curl with verbose debug options turned on to see what's going on.

4. If you're a network geek, you can capture the whole shebang using a tool such as tcpdump/wireshark.
 
Jf Okeeffe
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Examining the variables on Eclipse I've been doing already. But would like to have the request content in the format it is submitted through HTTP to make sure I understand exactly what is being submitted.
2. Yes, what I need is exactly what Chrome Dev Tools can display. The issue is that this is an API, not an webapp so I can't open it on the browser.
3 and 4. Not sure how to do this.
 
Tim Holloway
Saloon Keeper
Posts: 24499
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exact format of an HTTP request is defined in a series of documents called RFC's. These Request For Comment specs are published to establish various Internet standards for the web, email, and numerous other services. So to see how to form a legal HTTP request, you have to reference these documents

I think the latest RFC for HTTP is RFC6585. Basically, though, an HTTP request is text comprising a URL request, followed by headers, one per line, followed by 2 newline characters (making a blank line) followed by the request body which can be in POST form format (there's an RFC for that), or just general text like a JSON or YAML request string. Or an HTML GET. Or no body at all, like the API for my home automation system uses.

Essentially, though, it you are using a client library like Java's Http client library, all the basic stuff is guaranteed to be the right stuff in the right places. In fact, even automatically passing cookies back and forth, which is essential for maintaining HttpSessions on the server. So what you see in the servlet is going to be OK.

HTTPS is identical except that data is encrypted.

The HTTP format is deliberately simple and text-based. Back when the Internet was new, a lot of stuff got routed through multiple machines. Some used ASCII, some used EBCDIC, some were bytewise-discontinuous (DEC and later Intel), some bytewise-continuous (IBM, Motorola), different word lengths. Different byte lengths! The one thing they had in common was some sort of native text form that could (mostly) be automatically translated from machine to machine as it bounced along. This is also why Base64 is popular for MIME formatting of binary. Base64 is text and only uses characters that a 7-bit character set (such as the original ASCII) would have.

Another reason why text was so popular back then was that it was easy to test. You can literally use the telnet remote teletype application to submit HTTP GET and POST requests by simply typing in the HTTP data in the form I mentioned earlier. Unfortunately, telnet doesn't deal with things like HTML, however, so what you get back is going to be raw text. Email, incidentally, also can be tested this way!
 
Marshal
Posts: 3708
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:If you're a network geek, you can capture the whole shebang using a tool such as tcpdump/wireshark.


I do this quite often, but you will need privileged access to the hosting platform (typically command-line shell access).  Also if you are using HTTPS (HTTP over TLS) then it will be more challenging or maybe not possible at all.
 
Ron McLeod
Marshal
Posts: 3708
523
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the logging capabilities described in Apache HttpComponents Logging Practices:
 
Jf Okeeffe
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Ron. Thank you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic