Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP response code: 411 for URL: http://api.twitter.com/oauth/request_token
    text
    copied!<p>Modified:</p> <p>Reference :http://dev.twitter.com/pages/auth</p> <p>I have get signature_base_string,signature_key,oauth_signature and all other parameters that are the same with twitter tutorial.</p> <ol> <li><p>signature_base_string POST&amp;https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&amp;oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0</p></li> <li><p>signature_key oauth_consumer_secret="MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&amp;"</p></li> <li>oauth_signature 8wUi7m5HFQy76nowoCThusfgB+Q=</li> </ol> <p>Now I request <a href="http://api.twitter.com/oauth/request_token" rel="nofollow">http://api.twitter.com/oauth/request_token</a> use "POST" method and get response code 411. I use a servlet doGet() when I request it from my Firefox. What do I miss in the code or any mistake? Who can help me?</p> <pre><code> protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String base_url="http://api.twitter.com/oauth/request_token"; String oauth_callback="http://api.twitter.com/1/statuses/public_timeline.json"; String oauth_consumer_key="GDdmIQH6jhtmLUypg82g"; String oauth_consumer_secret="MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&amp;"; String oauth_signature_method="HMAC-SHA1"; int oauth_timestamp=1272323042; String oauth_version="1.0"; String oauth_nonce="QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk"; String oauth_signature=""; String signature_base_string = null; try { signature_base_string = "POST" + "&amp;" + URLEncoder.encode( "https://api.twitter.com/oauth/request_token", "UTF-8") + "&amp;" + URLEncoder .encode("oauth_callback=http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11&amp;oauth_consumer_key=GDdmIQH6jhtmLUypg82g&amp;oauth_nonce=QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1272323042&amp;oauth_version=1.0", "UTF-8"); System.out.println(signature_base_string); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec( oauth_consumer_secret.getBytes(), "HmacSHA1"); mac.init(secret); byte[] digest = mac.doFinal(signature_base_string.getBytes()); BASE64Encoder encoder = new BASE64Encoder(); oauth_signature=encoder.encode(digest); System.out.println(oauth_signature); } catch (Exception e) { System.out.println(e.getMessage()); } URL url=new URL(base_url); HttpURLConnection httpURLCon=(HttpURLConnection)url.openConnection(MyProxy.getProxy()); httpURLCon.setRequestMethod("POST"); httpURLCon.setRequestProperty("Authorization", "OAuth "+"oauth_nonce='QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', oauth_callback='http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11', oauth_signature_method='HMAC-SHA1', oauth_timestamp='1272323042', oauth_consumer_key='GDdmIQH6jhtmLUypg82g', oauth_signature='8wUi7m5HFQy76nowoCThusfgB%2BQ%3D', oauth_version='1.0'"); httpURLCon.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"); /*Map&lt;String,List&lt;String&gt;&gt; headers= httpURLCon.getHeaderFields(); Iterator&lt;String&gt; i=headers.keySet().iterator(); while(i.hasNext()){ String key=i.next(); System.out.println(key); System.out.println(headers.get(key).toString()); System.out.println("===================="); } */ httpURLCon.connect(); InputStream is=null; if (httpURLCon.getResponseCode() != 200) { is = httpURLCon.getErrorStream(); } else { is = httpURLCon.getInputStream(); } byte[] b=new byte[1024*4]; int read; while((read=is.read(b))!=-1){ response.getOutputStream().write(b,0,read); } } </code></pre> <p>Message: <strong>ERROR The requested URL could not be retrieved</strong></p> <p>While trying to process the request:</p> <p>POST /oauth/request_token HTTP/1.1 Host: api.twitter.com Authorization: OAuth oauth_nonce='QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', oauth_callback='http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11', oauth_signature_method='HMAC-SHA1', oauth_timestamp='1272323042', oauth_consumer_key='GDdmIQH6jhtmLUypg82g', oauth_signature='8wUi7m5HFQy76nowoCThusfgB%2BQ%3D', oauth_version='1.0' User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0 Cache-Control: no-cache Pragma: no-cache Accept: text/html, image/gif, image/jpeg, *; q=.2, <em>/</em>; q=.2 X-D-Forwarder: yes Max-Forwards: 10</p> <p>The following error was encountered:</p> <pre><code>Invalid Request </code></pre> <p>Some aspect of the HTTP Request is invalid. Possible problems:</p> <pre><code>Missing or unknown request method Missing URL Missing HTTP Identifier (HTTP/1.0) Request is too large Content-Length missing for POST or PUT requests Illegal character in hostname; underscores are not allowed </code></pre> <p>Your cache administrator is webmaster. Generated Fri, 08 Jul 2011 06:41:34 GMT by google.com (squid/2.7.STABLE6) </p> <p>==========================================================</p> <p>Reference :http://dev.twitter.com/pages/auth</p> <p>I have get signature_base_string,signature_key,oauth_signature and all other parameters that are the same with twitter tutorial.</p> <ol> <li><p>signature_base_string POST&amp;https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&amp;oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0</p></li> <li><p>signature_key oauth_consumer_secret="MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&amp;"</p></li> <li>oauth_signature 8wUi7m5HFQy76nowoCThusfgB+Q=</li> </ol> <p>Now I request <a href="http://api.twitter.com/oauth/request_token" rel="nofollow">http://api.twitter.com/oauth/request_token</a> use "POST" method and get response code 411. I use a servlet doGet() when I request it from my Firefox. What do I miss in the code or any mistake? Who can help me?</p> <pre><code> protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String base_url="http://api.twitter.com/oauth/request_token"; String oauth_callback="http://api.twitter.com/1/statuses/public_timeline.json"; String oauth_consumer_key="GDdmIQH6jhtmLUypg82g"; String oauth_consumer_secret="MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&amp;"; String oauth_signature_method="HMAC-SHA1"; int oauth_timestamp=1272323042; String oauth_version="1.0"; String oauth_nonce="QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk"; String oauth_signature=""; String signature_base_string = null; try { signature_base_string = "POST" + "&amp;" + URLEncoder.encode( "https://api.twitter.com/oauth/request_token", "UTF-8") + "&amp;" + URLEncoder .encode("oauth_callback=http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11&amp;oauth_consumer_key=GDdmIQH6jhtmLUypg82g&amp;oauth_nonce=QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk&amp;oauth_signature_method=HMAC-SHA1&amp;oauth_timestamp=1272323042&amp;oauth_version=1.0", "UTF-8"); System.out.println(signature_base_string); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec( oauth_consumer_secret.getBytes(), "HmacSHA1"); mac.init(secret); byte[] digest = mac.doFinal(signature_base_string.getBytes()); BASE64Encoder encoder = new BASE64Encoder(); oauth_signature=encoder.encode(digest); System.out.println(oauth_signature); } catch (Exception e) { System.out.println(e.getMessage()); } URL url=new URL(base_url); HttpURLConnection httpURLCon=(HttpURLConnection)url.openConnection(MyProxy.getProxy()); httpURLCon.setRequestMethod("POST"); httpURLCon.setRequestProperty("Authorization", "OAuth "+"oauth_nonce='QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk', oauth_callback='http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11', oauth_signature_method='HMAC-SHA1', oauth_timestamp='1272323042', oauth_consumer_key='GDdmIQH6jhtmLUypg82g', oauth_signature='8wUi7m5HFQy76nowoCThusfgB%2BQ%3D', oauth_version='1.0'"); httpURLCon.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"); /*Map&lt;String,List&lt;String&gt;&gt; headers= httpURLCon.getHeaderFields(); Iterator&lt;String&gt; i=headers.keySet().iterator(); while(i.hasNext()){ String key=i.next(); System.out.println(key); System.out.println(headers.get(key).toString()); System.out.println("===================="); } */ httpURLCon.connect(); InputStream is=httpURLCon.getInputStream(); byte[] b=new byte[1024*4]; int read; while((read=is.read(b))!=-1){ response.getOutputStream().write(b,0,read); } } </code></pre> <p>Exception:</p> <pre><code>java.io.IOException: Server returned HTTP response code: 411 for URL: http://api.twitter.com/oauth/request_token at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313) at com.twitterbridge.oauth.Oauth.doGet(Oauth.java:114) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) </code></pre>
 

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