Trying to read an URL using POST throws 400 BAD Request
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Manju_k
Posted On:   Thursday, March 27, 2003 11:19 AM

I am trying to read an xml using the HttpURLConnection class . If the method is set to GET the data which is an xml file is retrieved fine. If the method is set to POST then the getInputStream in HttpURLConnection throws a "400 Bad request' . The servlet handles both doGet() and doPost() i.e doPost() calls doGet() . This is using weblogic 7.0 . code snippet: con = url.openConnection(); con.setDoOutput(false); //con.setDoInput(true); con.setAllowUserInteraction(false); //((HttpURLConnection)con).setRequestMethod("GET"); ((HttpURLConnection)con).setRequestMethod("POST"); ((HttpURLConnection)con).setRequestProper   More>>


I am trying to read an xml using the HttpURLConnection class . If the method is set to GET the data which is an xml file is retrieved fine. If the method is set to POST then the getInputStream in HttpURLConnection throws a "400 Bad request' .



The servlet handles both doGet() and doPost() i.e doPost() calls doGet() .


This is using weblogic 7.0 .

code snippet:
con = url.openConnection();

con.setDoOutput(false);

//con.setDoInput(true);

con.setAllowUserInteraction(false);

//((HttpURLConnection)con).setRequestMethod("GET");

((HttpURLConnection)con).setRequestMethod("POST");


((HttpURLConnection)con).setRequestProperty("Content-type", "text/html; charset=UTF-8");


File f = new File(directory);

f.mkdir();

System.out.println(" url : " + con.toString() );

System.out.println(" url : " + ((HttpURLConnection)con).usingProxy() );

con.connect();

in = con.getInputStream();
   <<Less

Re: Trying to read an URL using POST throws 400 BAD Request

Posted By:   Ni_zhen  
Posted On:   Thursday, March 27, 2003 05:41 PM

confirm ur url'protocol is correctly,such as "ftp,http,file...",then the url's hostname,port,path and file.


ie.

http://myserver:1234/somepath/somefile

ftp://myserver/somepath/somefile

file:///somepath/somefile

About | Sitemap | Contact