Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP 403 Service Error when trying to post XML to HTTPS URL
    primarykey
    data
    text
    <p>I am trying to write a small class using the Apache HttpClient library that would do an HTTPS post to a specified URL sending some XML. When I run my code, the HTTP status line I receive back is "403 Service Error". Here's the complete error HTML returned:</p> <pre><code>$errorDump java.net.SocketTimeoutException:Read timed out $errorInfo $errorDump java.net.SocketTimeoutException:Read timed out $error Read timed out $localizedError Read timed out $errorType java.net.SocketTimeoutException $user $time 2011-10-25 09:39:29 EDT $error Read timed out $errorType java.net.SocketTimeoutException </code></pre> <p>This is the code I am using:</p> <pre><code>import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; public class HttpXmlPost { public static void main(String[] args) { String url = "https://someurlhere.com"; String xmlStr = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;&lt;xmlTag&gt;&lt;/xmlTag&gt;"; String content = request(xmlStr, url); System.out.println(content); } private static String request(String xmlStr, String url) { boolean success = false; String content = ""; HttpClient httpclient = new DefaultHttpClient(); try { HttpPost httpPost = new HttpPost(url.trim()); InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(xmlStr.getBytes() ), -1); reqEntity.setContentType("application/xml"); reqEntity.setChunked(true); httpPost.setEntity(reqEntity); System.out.println("Executing request " + httpPost.getRequestLine()); HttpResponse response = httpclient.execute(httpPost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if(response.getStatusLine().getStatusCode() == 200){ success = true; } if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); } BufferedReader reader = new BufferedReader(new InputStreamReader(resEntity.getContent())); StringBuilder buf = new StringBuilder(); char[] cbuf = new char[ 2048 ]; int num; while ( -1 != (num=reader.read( cbuf ))) { buf.append( cbuf, 0, num ); } content = buf.toString(); EntityUtils.consume(resEntity); } catch (Exception e) { System.out.println(e); } finally { httpclient.getConnectionManager().shutdown(); } return content; } } </code></pre> <p>Whatever XML I pass in doesn't seem to matter, it gives the same error no matter what. Note that this actually works with some URLs. For example, if I put <a href="https://www.facebook.com" rel="nofollow">https://www.facebook.com</a>, it goes through. However, it doesn't work for my specified URL. I thought it might be a certificate issue, tried to add some code to trust any certificate, didn't seem to work either, though I may have done it wrong. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload