簡體   English   中英

訪問php Web服務時出錯

[英]Error in accessing php web service

我正在用由byethost.com托管的php編寫Web服務,它在瀏覽器以及“ http://www.jsoneditoronline.org/ ”上均能正常工作。 但是當我從android應用程序調用服務時,它給出了錯誤。

05-06 00:31:34.475:E / AndroidRuntime(24246):java.lang.IllegalArgumentException:主機名不能為空05-06 00:31:34.475:E / AndroidRuntime(24246):在org.apache.http .HttpHost。(HttpHost.java:83)05-06 00:31:34.475:E / AndroidRuntime(24246):位於org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:519)05-06 00:31:34.475:E / AndroidRuntime(24246):位於org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)05-06 00:31:34.475:E / AndroidRuntime(24246):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)05-06 00:31:34.475:E / AndroidRuntime(24246):在com.shreeji.jsonparser.JSONParser.getJSONFromUrl(JSONParser。 java:47)05-06 00:31:34.475:E / AndroidRuntime(24246):at apidatahandler.TilesApiCall.getTilesDetails(TilesApiCall.java:23)05-06 00:31:34.475:E / AndroidRuntime(24246):at com.shreejitiles.android.Ui_MainPage $ 1.run(Ui_MainPage.java:41)05-06 00:31:34.475:E / AndroidRuntime(24246):at java.l ang.Thread.run(Thread.java:856)

請幫我。

我用來解析的代碼從服務器獲取響應。

package com.shreeji.jsonparser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {

    }

    public JSONObject getJSONFromUrl(String url, List<NameValuePair> params)
            throws ClientProtocolException, IOException, JSONException {

        Log.i("url", url);

        // Making HTTP request

        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(is,
                "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();

        jObj = new JSONObject(json);

        // return JSON String
        return jObj;

    }
}

這是因為您尚未為請求設置主機網址。

暫無
暫無

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

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