try{
JSONObject user = new JSONObject();
user.put("TrueName",User);
user.put("UserPwd",Pwd);
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> pair = new ArrayList<NameValuePair>();
pair.add(new BasicNameValuePair("type","login"));
pair.add(new BasicNameValuePair("json", user.toString()));
httpPost.setEntity(new UrlEncodedFormEntity(pair, HTTP.UTF_8));
HttpResponse resp = new DefaultHttpClient().execute(httpPost);
if(resp.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str=EntityUtils.toString(resp.getEntity());
Toast.makeText(MainActivity.this,""+str,Toast.LENGTH_LONG).show();
return true;
}else{
return false;
}
}catch (JSONException e)
这些语句应该没有问题吧?可怎么就提取不了后台的数据?后台是C#语言做的。
{
e.printStackTrace();
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
JSONObject user = new JSONObject();
user.put("TrueName",User);
user.put("UserPwd",Pwd);
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> pair = new ArrayList<NameValuePair>();
pair.add(new BasicNameValuePair("type","login"));
pair.add(new BasicNameValuePair("json", user.toString()));
httpPost.setEntity(new UrlEncodedFormEntity(pair, HTTP.UTF_8));
HttpResponse resp = new DefaultHttpClient().execute(httpPost);
if(resp.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
String str=EntityUtils.toString(resp.getEntity());
Toast.makeText(MainActivity.this,""+str,Toast.LENGTH_LONG).show();
return true;
}else{
return false;
}
}catch (JSONException e)
这些语句应该没有问题吧?可怎么就提取不了后台的数据?后台是C#语言做的。
{
e.printStackTrace();
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
解决方案 »
- android编译时没错误,但是不能执行,求救!
- 【做过的来】android分辨率自适应问题【有没有好的解决方案】
- MTK6573智能机平台系统文件夹文件详解2-build.prop
- 进公司不到一个月,想辞职重新找工作
- 做Android 哪一方面的开发好呢?
- android webserver 调用 帮我看看是哪里出啦错误为什么source not found
- 怎么讲图片资源的drawable类里面的静态常量读到数组里面去
- Android设备显示PC端实时采集的视频
- Android游戏服务端如何部署到云开放平台或者其他服务器上
- popuwindows 如何实现边框 阴影 不是整个手机界面半透明
- 求手机开发大神帮忙
- 关于tabhost中进行参数传递的问题
有什么问题的话把出错提示LogCat里面信息发上来。
08-07 08:25:50.251: INFO/ActivityManager(66): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.sailong.waiter/.MainActivity }
08-07 08:25:55.051: DEBUG/dalvikvm(579): GC_EXTERNAL_ALLOC freed 3321 objects / 267928 bytes in 180ms
08-07 08:25:57.284: INFO/ActivityManager(66): Displayed activity com.sailong.waiter/.MainActivity: 6245 ms (total 6245 ms)
08-07 08:26:02.980: DEBUG/dalvikvm(579): GC_FOR_MALLOC freed 626 objects / 25304 bytes in 137ms
08-07 08:26:08.640: WARN/InputManagerService(66): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@481ac458
08-07 08:26:09.360: DEBUG/dalvikvm(127): GC_EXPLICIT freed 190 objects / 9480 bytes in 4199ms
2.看看你的权限添加了没有,访问网络的权限。
另:你给的log里面没有exception啥的,没啥价值啊
是的 new Thread(new Runnable()
{
@Override
public void run()
{
网络通讯代码写在这里
}
}).start();