File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Fake a post request from java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Fake a post request from java class" Watch "Fake a post request from java class" New topic
Author

Fake a post request from java class

hura fly
Greenhorn

Joined: May 10, 2010
Posts: 3
Hi all,

I'm a new comer here, nice to meet you all. I have a problem and need your help.
I send a post request from my java class but the target page doesn't process my request.
This is my source code, I think there's no problem in my source:


and the url I use is:
http://noip.gov.vn/noip/feedback.nsf/frmFeedbackv3?OpenForm&Language=English
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

"hura no name", please check your private messages regarding an important administrative matter.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
That's a lot of code. What, exactly, happens if you run it? "doesn't process" gives us nothing to work with. Have you used an HTTP monitoring tool (like the Firefox extension LiveHttpHeaders) to observe how the HTTP sent by browser is different from the HTTP sent by your code?


Ping & DNS - updated with new look and Ping home screen widget
hura fly
Greenhorn

Joined: May 10, 2010
Posts: 3
Ulf Dittmer wrote:That's a lot of code. What, exactly, happens if you run it? "doesn't process" gives us nothing to work with. Have you used an HTTP monitoring tool (like the Firefox extension LiveHttpHeaders) to observe how the HTTP sent by browser is different from the HTTP sent by your code?

Sry for not very clear explaination.

When I run that code, the content of the response I get is the same as the page that contains the form.Let's say, I have a form A, I submit it with parameter then it should return me "Submit success" or "Submit failed". But what I receive is still the form A.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
OK.
Ulf Dittmer wrote:Have you used an HTTP monitoring tool (like the Firefox extension LiveHttpHeaders) to observe how the HTTP sent by the browser is different from the HTTP sent by your code?
hura fly
Greenhorn

Joined: May 10, 2010
Posts: 3
Ulf Dittmer wrote:OK.
Ulf Dittmer wrote:Have you used an HTTP monitoring tool (like the Firefox extension LiveHttpHeaders) to observe how the HTTP sent by the browser is different from the HTTP sent by your code?


I've just install LiveHttp headers add-on.
When I submit form from firefox, I can see the sent data that I input the form. Then I clear the content of LiveHttp and run my java source -> nothing happens, the LiveHttp is empty.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
Then I clear the content of LiveHttp and run my java source -> nothing happens, the LiveHttp is empty.

Of course it is. It's a browser plugin, so it can be used to monitor browser traffic, not any HTTP traffic originating from your machine. But you can use its output to compare it to your Java source code, to see whether that would generate the same output.

If you want to monitor all HTTP traffic, use an HTTP proxy.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Too many comments :(
Tushar Kapila
Ranch Hand

Joined: Dec 23, 2007
Posts: 35

one of the problems is that you need to append the GET params (the name-value pairs after the ? mark in the target URL) in the post string too (see code lines 229 to 231 below) ...

good advice - if you have the time is to use: apache http client http://hc.apache.org/ . will be better in the long run ... more robust and covers more cases including file upload, authorization etc

if you do not want something so heavy can use this code








http://thehungersite.com | http://www.worldcommunitygrid.org/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fake a post request from java class
 
Similar Threads
Login to web server with HttpClient
post url connection not working
error while submitting an http web request
Logging into a forum
POST and Get Http Method