7

How do you do do an HTTP PUT? The class I'm using seems to think it is doing a PUT but the endpoint is treating it as if I did a GET. Am I doing anything wrong?

URL url = new URL("https://...");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("PUT");

OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

writer.write(xmlString);
writer.close();

System.out.println(conn.getRequestMethod());
String response = readInputStream(conn.getInputStream());
System.out.println(response);

Which is printing:

PUT
<same content as doing a GET>

I'd rather not include another library if this one could work...

0

1 Answer 1

5

There's one easy way to find out: run Wireshark and see what's actually happening on the network. I've found that to be the most reliable way of diagnosing this sort of issue - your client could have bugs, the library could have bugs, the server could have bugs, but Wireshark will show you what's really happening.

EDIT: Okay, for HTTPS it's a little trickier. You can use Fiddler if you're running on Windows, which is a proxy - it can cope with HTTPS if you can persuade your client code to accept its certificate, but that's a little more intrusive... putting a proxy in the way clearly changes what the traffic looks like.

It would be better if you could talk to a debug version of the server over HTTP instead. Is that feasible in your case, or is the server completely outside your control?

Sign up to request clarification or add additional context in comments.

2 Comments

All my traffic is https to the remote server... and wireshark can't see much inside of there. Hitting it with curl vs from java DOES look different, but what should I be looking for?
Good idea. I contacted them and got a HTTP server for testing. I found my problem was the lack of a Content-Type header being rejected by their server. Thanks so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.