乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Server returned HTTP response code: 500

       日月桃子 2016-06-02
           今天做項(xiàng)目,需要跟第三方通信,用第三方的 httpclient 可以正常請(qǐng)求。但是換用下面的代碼。確返回 Server returned HTTP response code: 500

      當(dāng)時(shí),我一想,不對(duì)呀,第三方請(qǐng)求可以,而且直接用瀏覽器用地址也可以正常訪問,那為什么會(huì)返回提示這個(gè)呢?

      前提,頭信息,對(duì)方是 text/xml 編碼 utf-8

      代碼如下:


      try {
      URL urls = new URL(url);
      HttpURLConnection uc = (HttpURLConnection) urls.openConnection();
      uc.setRequestMethod("POST");
      uc.setRequestProperty("ContentType","text/xml;charset=utf-8");
      uc.setRequestProperty("charset", "UTF-8");

      //uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT //5.1)AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11");

      uc.setDoOutput(true);
      uc.setDoInput(true);
      //uc.setReadTimeout(10000);
      //uc.setConnectTimeout(10000);
      if(!StringUtils.isBlank(message)){
      DataOutputStream dos = new       DataOutputStream(uc.getOutputStream());
      dos.write(message.getBytes("UTF-8"));
      dos.flush();
      }
      BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
      String readLine = "";
      while ((readLine = in.readLine()) != null) {
      sb.append(readLine);
      }
      in.close();
      } catch (Exception e) {
      e.printStackTrace();
      }finally{
                               ///釋放資源

      }


      注意看粗體,主要是這個(gè)頭信息設(shè)置有誤,導(dǎo)致服務(wù)器返回 500錯(cuò)誤。。
      另外,在網(wǎng)上也GOOLGE了下,也有的是說是第二個(gè)粗字體處,沒有設(shè)置的原因,說是安全性。
      以此記錄下。   
      原文鏈接:http://wrong1111./blog/1455191


      HttpClient的使用模式:

      1. 創(chuàng)建一個(gè)HttpClient  

      2.實(shí)例化新的HTTP方法,比如PostMethod 或 GetMethod

      3.設(shè)置HTTP參數(shù)名稱/值

      4.使用HttpClient  執(zhí)行HTTP調(diào)用

      5.處理Http響應(yīng)

       

      如下代碼使用HttpClient  獲取HttpGet請(qǐng)求:

      Java代碼  收藏代碼
      1. public class TestHttpGet {  
      2.   
      3.     public String executeGet(String url) throws Exception {  
      4.         BufferedReader in = null;  
      5.   
      6.         String content = null;  
      7.         try {  
      8.             // 定義HttpClient  
      9.             HttpClient client = new DefaultHttpClient();  
      10.             // 實(shí)例化HTTP方法  
      11.             HttpGet request = new HttpGet();  
      12.             request.setURI(new URI(url));  
      13.             HttpResponse response = client.execute(request);  
      14.   
      15.             in = new BufferedReader(new InputStreamReader(response.getEntity()  
      16.                     .getContent()));  
      17.             StringBuffer sb = new StringBuffer("");  
      18.             String line = "";  
      19.             String NL = System.getProperty("line.separator");  
      20.             while ((line = in.readLine()) != null) {  
      21.                 sb.append(line + NL);  
      22.             }  
      23.             in.close();  
      24.             content = sb.toString();  
      25.         } finally {  
      26.             if (in != null) {  
      27.                 try {  
      28.                     in.close();// 最后要關(guān)閉BufferedReader  
      29.                 } catch (Exception e) {  
      30.                     e.printStackTrace();  
      31.                 }  
      32.             }  
      33.             return content;  
      34.         }  
      35.     }  
      36.   
      37.       
      38.   
      39. }  

      原文鏈接:http://ipfire./blog/978063

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多