我有我的web服務寫在PHP託管在byethost.com 它工作正常,瀏覽器和「http://www.jsoneditoronline.org/」。 但是,當我從android應用程序調用服務時,它會給出錯誤。錯誤訪問php的網絡服務
05-06 00:31:34.475:E/AndroidRuntime(24246):java.lang.IllegalArgumentException異常:主機名可以不爲空 05-06 00:31:34.475:E/AndroidRuntime(24246) :at org.apache.http.HttpHost。(HttpHost.java:83) 05-06 00:31:34.475:E/AndroidRuntime(24246):at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient .java:519) 05-06 00:31:34.475:E/AndroidRuntime(24246):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509) 05-06 00:31 :34.475:E/AndroidRuntime(24246):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 05-06 00:31:34.475:E/AndroidRuntime(24246):at com .shreej E/AndroidRuntime(24246):at apidatahandler.TilesApiCall.getTilesDetails(TilesApiCall.java:23) 05-06 00: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.lang .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;
}
}
我設置的網址與我正在嘗試瀏覽器相同 http://www.example.byethost18.com/Api/getWalltiles.php?action=1 ,但它在瀏覽器中正常工作,而不是在android應用程序中正常工作。 – warlock 2013-05-05 19:36:02
沒有,但dosent工作相同的錯誤味精。 我也試過要求url或hurl.it bur它不會在那裏工作。 它在我的瀏覽器中正常工作。 – warlock 2013-05-05 19:41:34
你可以發佈你的代碼嗎? – 2013-05-05 19:42:25