android HTTP请求响应的问题 url="http://192.168.1.168:8080/sshop_Server/servlet/LoginServlet?username=username&password=password" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其中username=username&password=password是动态添加的 username=username&password=password????你这里面username和password都放到字符串里面去了,怎么传值进去呢。。改成:url="http://192.168.1.168:8080/sshop_Server/servlet/LoginServlet?username="+username+"&password="+password; 那是我在运行过程中在debug时取出来的url的值 看你URL应该使用get方法吧、你现在用的post 当然报错了这是之前写的,你看下String uriAPI="http://10.255.153.46:8080/Registe/servlet/reg?user="+s0+"&password="+s1; String strResult; HttpGet httpRequest=new HttpGet(uriAPI);//创建HTTP Get连接 try { HttpClient client = new DefaultHttpClient(); client.execute(httpRequest); HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest); if(httpResponse.getStatusLine().getStatusCode()==200){ //当访问服务器有效时 strResult=EntityUtils.toString(httpResponse.getEntity()).trim(); Log.d("Infor","新用户:"+strResult); if(strResult.equals("Y")){ new AlertDialog.Builder(Register1.this).setTitle(" 提示") .setMessage("注册成功!!") .setPositiveButton("确定", null) .show();} else if(strResult.equals("N")){ new AlertDialog.Builder(Register1.this).setTitle(" 提示") .setMessage("注册失败,该账号已被使用!!") .setPositiveButton("确定", null) .show();} } else{ //System.out.println(httpResponse.getStatusLine().getStatusCode()); Log.d("Infor","连接失败"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e); } 代码没问题,但是我没看到你在httpPost那里哪边添加参数值了啊要是代码中的方法的参数url为你debug中的值,貌似这是HttpGet方式请求的啊,httpPost就改成httpGet如果你一定要用post方式,需要httpPost.setEntity(HttpEntity entity); post请求的时候参数不应该设置在url里,楼上说的都是这个问题 问题差不多我的url是这么设置的但执行操作就出现错误地址在浏览器执行却没有任何问题URI uri = new URI(httpUrl); request.setURI(uri);问题出在哪都找不到因为客户端无错误时后台错了 Android4.2.2中去掉Picasa android性能优化问题 我自己的apk应用程序能否创建一个守护进程? 如何清空android ListView控件的内容 layout编辑试图不见了 安卓系统,图片3D效果化单子,高手的进来 如何实现自动登录问题 android socket 连接问题! Google 地图显示不出来,求教 急求! webView长按的自由复制功能怎么手动调用和修改 为什么我的setImageBitmap 显示不出来图像? android起始页
你这里面username和password都放到字符串里面去了,怎么传值进去呢。。
改成:url="http://192.168.1.168:8080/sshop_Server/servlet/LoginServlet?username="+username+"&password="+password;
这是之前写的,你看下
String uriAPI="http://10.255.153.46:8080/Registe/servlet/reg?user="+s0+"&password="+s1;
String strResult;
HttpGet httpRequest=new HttpGet(uriAPI);//创建HTTP Get连接
try {
HttpClient client = new DefaultHttpClient();
client.execute(httpRequest);
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode()==200){ //当访问服务器有效时
strResult=EntityUtils.toString(httpResponse.getEntity()).trim();
Log.d("Infor","新用户:"+strResult);
if(strResult.equals("Y")){
new AlertDialog.Builder(Register1.this).setTitle(" 提示") .setMessage("注册成功!!") .setPositiveButton("确定", null) .show();}
else if(strResult.equals("N")){
new AlertDialog.Builder(Register1.this).setTitle(" 提示") .setMessage("注册失败,该账号已被使用!!") .setPositiveButton("确定", null) .show();}
}
else{
//System.out.println(httpResponse.getStatusLine().getStatusCode());
Log.d("Infor","连接失败");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
}
要是代码中的方法的参数url为你debug中的值,貌似这是HttpGet方式请求的啊,httpPost就改成httpGet
如果你一定要用post方式,需要httpPost.setEntity(HttpEntity entity);
URI uri = new URI(httpUrl);
request.setURI(uri);
问题出在哪都找不到因为客户端无错误时后台错了