public void connectSend()//客户端发送连接请求
{
final String urlAP;";
HttpPost httpRequest = new HttpPost(urlAPI);
List <NameValuePair> params = new ArrayList <NameValuePair>();
String x=et1.getText().toString();
String x1=et2.getText().toString();
params.add(new BasicNameValuePair("str",URLEncoder.encode(x)));
params.add(new BasicNameValuePair("str1",URLEncoder.encode(x1)));
try
{
/*发叨HTTP request*/
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/*取得HTTP response*/
/* HttpResponse execute (HttpUriRequest request)
* 通过HttpUriRequest对象执行返回一个HttpResponse对象
*/
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
/*若状态码为200*/
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
/*获取字符串*/
strResult=EntityUtils.toString(httpResponse.getEntity(),"UTF-8");
if(strResult!=null)
{
System.out.println(strResult);
divideString(strResult);//将字符串拆分为对象
Toast.makeText(MainActivity.this,"登陆成功", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(MainActivity.this,"用户名和密码不匹配", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "网络连接失败", Toast.LENGTH_SHORT).show();
}
}
catch (ClientProtocolException e)
{
Toast.makeText(MainActivity.this, "网络连接失败", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
catch (IOException e)
{
Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
catch (Exception e)
{
Toast.makeText(MainActivity.this, "失败", Toast.LENGTH_SHORT).show();
e.printStackTrace();
这是 传数据 有人能给我说说 用 httpClient怎么给服务器穿照片,,,非常感谢。。。