I am trying to do a PATCH Request. Everything works fine in c# but it doesn't work in Java.
The source code:
String url = postURL;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("X-HTTP-Method-Override", "PATCH");
con.setRequestProperty("Authorization", authInfo);
con.setRequestProperty("PublicKey", publicKey);
con.setRequestProperty("Content-Type", contenttype);
String toPost = "{\"StockQuantity\":"+newVal+"}";
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(toPost);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + toPost);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
I get the error:
Exception in thread "main" java.io.FileNotFoundException: https://www.pyewxo-onlineshop.de/odata/ProductVariantAttributeCombination(1757)
Full Stack trace:
Exception in thread "main" java.io.FileNotFoundException: https://www.xsadsaaf-onlineshop.de/odata/ProductVariantAttributeCombination(1757) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1926) at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1921) at java.security.AccessController.doPrivileged(Native Method) at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1920) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1490) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) at communication.ServerCommunication.reqPost(ServerCommunication.java:150) at xsadsaaf.xsadsaaf.main(xsadsaaf.java:48) Caused by: java.io.FileNotFoundException: https://www.xsadsaaf-onlineshop.de/odata/ProductVariantAttributeCombination(1757) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) at communication.ServerCommunication.reqPost(ServerCommunication.java:144) ... 1 more
The response code is: 404
With the same url, I can do a request in C#, why not in Java?