08-07-2008 03:53 PM
Hi, i am trying to write data to a web service as follows:
HttpConnection hConn = null; OutputStream outS = null; hConn = (HttpConnection) (Connector.open("http://something.com:8080/BBwebse
rvice/BBTracker.asmx?op=ReportInfo")); hConn.setRequestMethod(HttpConnection.POST); outS = hConn.openOutputStream(); outS.write(data.getBytes()); start = false; sending = false; outS.flush(); int responseCode = hConn.getResponseCode(); res2 = hConn.getResponseMessage(); if (responseCode == HttpConnection.HTTP_OK) sendResult = true; else sendResult = false;
The webservice "ReportInfo" method is supposed to recieve the data written and then save it to a data base. But it is not working
Any help is appreciated.
08-08-2008 10:17 AM
Not sure if this will help, but I'm connecting to a .NET web service just using the raw Http/Https Connection objects in java. In my code, I'm setting a few properties on the HttpsConnection object prior to writing data in the post.
In addition to setting the POST request method, I also make the following calls
httpConnection.setRequestProperty("Content-Type", "text/xml"); httpConnection.setRequestProperty("Content-Length"
, String.valueOf(sendBuffer.length)); // sendBuffer are the bytes to be written httpConnection.setRequestProperty("SOAPAction", {Soap namespace + Soap method here}); httpConnection.setRequestProperty("User-Agent", {User Agent String here});
If you are not using a SOAP web service then you can probably ignore that one. And I'm not sure if the user-agent is truly needed.
08-08-2008 12:03 PM - edited 08-08-2008 12:05 PM
HttpConnection hConn = null; OutputStream outS = null; hConn = (HttpConnection) (Connector.open("http://mywebservice.com:8080/BBwe
bservice/BBTracker.asmx?op=ReportInfo")); String login = "123456789:Password"; byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false); hConn.setRequestProperty("Authorization", "Basic " + new String(encoded)); hConn.setRequestProperty("Content-Type", "text/xml"); hConn.setRequestProperty("Content-Length", String.valueOf(data.length())); hConn.setRequestProperty("SOAPAction", "ReportInfo"); hConn.setRequestMethod(HttpConnection.POST); outS = hConn.openOutputStream(); outS.write(data.getBytes()); start = false; sending = false; outS.flush(); int responseCode = hConn.getResponseCode(); res2 = hConn.getResponseMessage(); if (responseCode == HttpConnection.HTTP_OK) sendResult = true; else sendResult = false;
Thanks Ryan,
Updated my code to that, getting an "Proxy Authentication Error" in the response message. also do i need to inclunde the op=ReportInfo in the URL?
Any suggestions?
08-11-2008 09:22 AM
08-11-2008 09:55 AM
It sounds like a problem on the server side. How is your web service security configured? Is it setup for Basic Auth or one of Microsoft's "better" versions of it? You may also want to check to see if there is any error in your server's event logs which may indicate why your web service is rejecting the request. Which http response code are you getting?