導航:首頁 > 網路信息 > 網站報錯505是什麼意思

網站報錯505是什麼意思

發布時間:2023-09-04 10:25:50

java調用URL錯誤,報505

HttpURLConnection 請求中 參數中如果有 空格,請求則會 505錯誤


解決: 需要對有空格的參數 做URL編碼處理。

importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.net.MalformedURLException;
importjava.net.URL;
importjava.net.URLEncoder;

importsun.net.www.protocol.http.HttpURLConnection;

importcom.alibaba.fastjson.JSONObject;


{
="http://localhost:8080/agd-restful/services/restful/QueryService/queryData/*?queryParam=";

publicstaticvoidmain(String[]args)
{
JSONObjectobj=newJSONObject();
obj.put("XM","匡匡");
obj.put("BIRTHDAY",<spanstyle="color:#FF6666;">getURLEncoder</span>("1988-01-0100:00:00,1988-12-3000:00:00"));

Stringurls=targetURL+obj.toString();
requestRestServer(urls);

}

(Stringurl)
{
JSONObjectobj=newJSONObject();
try
{
URLrestServiceURL=newURL(url);

=(HttpURLConnection)restServiceURL.openConnection();
httpConnection.setRequestMethod("GET");
httpConnection.setRequestProperty("Accept","application/json");
httpConnection.setRequestProperty("Accept-Charset","UTF-8");
httpConnection.setRequestProperty("contentType","UTF-8");

if(httpConnection.getResponseCode()!=200){
thrownewRuntimeException(":"
+httpConnection.getResponseCode());
}

BufferedReaderresponseBuffer=newBufferedReader(newInputStreamReader(
(httpConnection.getInputStream()),"utf-8"));

Stringoutput="";
Stringresult="";
System.out.println("OutputfromServer: ");

while((output=responseBuffer.readLine())!=null){
//System.out.println(output);
result=output;
}
obj=JSONObject.parseObject(result);
System.out.println(obj.toString());
httpConnection.disconnect();

}catch(MalformedURLExceptione){

e.printStackTrace();

}catch(IOExceptione){
e.printStackTrace();

}
returnobj;
}

@SuppressWarnings("deprecation")
<spanstyle="color:#FF6666;">(Stringdest)
{
returnURLEncoder.encode(dest);
}</span>
}

修改後 正常ok

閱讀全文

與網站報錯505是什麼意思相關的資料

熱點內容
如何刪除mac系統文件夾在哪 瀏覽:122
網路項目設備漏配會造成什麼後果 瀏覽:707
發表論文哪個網站好 瀏覽:102
編程玩具課是什麼 瀏覽:426
網路盒子信號線怎麼焊接 瀏覽:65
cdr透視工具 瀏覽:125
u盤來回弄裡面的文件 瀏覽:247
如何將編程寫進晶元 瀏覽:184
安卓手機內存升級軟體下載 瀏覽:747
Excel共享文件內容沒有了 瀏覽:282
電腦連接無線一直顯示正在獲取網路地址 瀏覽:760
微信1元3包紅包尾數概率分析 瀏覽:799
如何改變網站名稱 瀏覽:919
熊貓看書哪個文件夾 瀏覽:650
win10勒索文件保護設置 瀏覽:842
arcgissde93安裝教程 瀏覽:487
xml文件注釋快捷鍵 瀏覽:878
extjs的配置文件怎麼配置重定向 瀏覽:740
access資料庫查看aspx 瀏覽:154
數控編程如何減少時間 瀏覽:779

友情鏈接