我正在开发Android应用程序。我已将我的应用程序连接到宁静的Web服务。每当我连接网络时,我的IP地址都会被更改。所以我想设置静态IP地址。但我已尝试通过网络共享属性静态IP地址。但它不起作用。有人可以帮帮我吗?
答案 0 :(得分:0)
你可以尝试代码:
public static final String URLPREFIX = "http://url/api";
HttpGet httpget = new HttpGet(URLPREFIX + "/method_name/token/"
+ mAuthKey);
Log.e(TAG, "" + URLPREFIX + "/method_name/token/" + mAuthKey);
try {
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String jsonResponse = EntityUtils.toString(entity);
Log.e(TAG, "entity: " + jsonResponse);
JSONObject jsonObject = new JSONObject(jsonResponse);
JSONArray jsonArray = jsonObject.getJSONArray("collection");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject mFirstChild = jsonArray.getJSONObject(i);
int mId = Integer.parseInt(mFirstChild.getString("id"));
String mTitle = mFirstChild.getString("title");
arrayList.add(new CustomClass(mId, mTitle));
}
} catch (Exception e) {
e.printStackTrace();
}