簡體   English   中英

android get request exception“ java.lang.IllegalStateException:目標主機不得為null,或在參數中進行設置。

[英]android get request exception "java.lang.IllegalStateException: Target host must not be null, or set in parameters.

android get request exception“ java.lang.IllegalStateException:目標主機不能為null或在參數中設置。scheme = null,host = null,path = http://stage1-go.university:80/user/profile { userId“:” 0“}”

嗨,我試圖發出Get請求,代碼在這里:

public InputStream setGetRequest(String concreteUrl, String jsonAsString) throws IOException {
        String url = protocol + siteUrl + ":" + httpPort + "/" +  concreteUrl + jsonAsString;
        url = URLEncoder.encode(url, "UTF-8");

        HttpGet httpGet = new HttpGet(url);
        httpGet.setHeader("sessid", ClientAPI.getSessionId());

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        HttpClient client = new DefaultHttpClient();

        String getServerString = client.execute(httpGet, responseHandler);
        return null;
    }

這是我的日志:

12-11 17:59:50.731    2715-2733/com.podorojnik E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-312
    Process: com.podorojnik, PID: 2715
    java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://stage1-go.university:80/user/profile{"userId":"0"}
            at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591)
            at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
            at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
            at com.zeoalliance.internship.pilotproject.server.NetworkRequest.setGetRequest(NetworkRequest.java:100)
            at com.zeoalliance.internship.pilotproject.server.NetworkRequest.getInputStream(NetworkRequest.java:60)
            at com.zeoalliance.internship.pilotproject.server.NetworkRequest.execute(NetworkRequest.java:45)
            at com.zeoalliance.internship.pilotproject.server.ClientAPI.getUserProfile(ClientAPI.java:156)
            at com.zeoalliance.internship.pilotproject.activities.MainActivity$1.run(MainActivity.java:58)
            at java.lang.Thread.run(Thread.java:818)

我還在清單中添加了特殊權限,但對我沒有幫助

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

有人可以幫忙嗎?

您直接返回空值;

在您的setGetRequest方法中,輸入以下代碼:

String getServerString = client.execute(httpGet, responseHandler);
        return getServerString ;

代替:

String getServerString = client.execute(httpGet, responseHandler);
        return null;

請享用!!!

您將路徑設置為:

path=http://stage1-go.university:80/

stage1-go.university不是主機,甚至不是有效的URL。 需要一個頂級域名,例如.com,.net或類似的域名。 如果這行得通,您應該可以在任何瀏覽器中訪問http://stage1-go.university ,但是那行不通-我只是嘗試了一下

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM