请教各位大大,android访问不了本地服务器
来源:互联网 发布:js中target什么意思 编辑:程序博客网 时间:2024/06/06 06:44
服务器在Tomcat上,安卓上需要访问,一点登录就崩溃了,代码如下:
崩溃在
package com.example.queryresults;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
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.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView resultsTV = (TextView)findViewById(R.id.t1);
EditText Num = (EditText)findViewById(R.id.Num);
EditText Key = (EditText)findViewById(R.id.Key);
Button OK = (Button)findViewById(R.id.OK);
final String num = Num.getText().toString();
final String key = Key.getText().toString();
OK.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String results = "";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpRequest = new HttpPost("http://100.78.23.200:8080/QueryResults/Login");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Num",num));
params.add(new BasicNameValuePair("Key",key));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params,"utf-8"));
/*这里出错,是不是地址的问题,在虚拟机上抛的*/
HttpResponse httpResponse = httpclient.execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
results += EntityUtils.toString(httpResponse.getEntity());
}else{
results = "请求失败!";
}
resultsTV.setText(results);
} catch (UnsupportedEncodingException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
崩溃在
HttpResponse httpResponse = httpclient.execute(httpRequest);
0 0
- 请教各位大大,android访问不了本地服务器
- 请教各位大大,android访问不了本地服务器
- 各位大大~~请教一个问题~
- 新人向各位大大请教一个问题
- android访问本地服务器
- 关于阿里云服务器本地访问不了的问题
- android模拟器访问本地服务器
- Android模拟器访问本地服务器
- Android模拟器访问本地服务器
- android访问本地Web服务器
- Android模拟器访问本地服务器
- 请教各位!
- 请教各位
- 请教各位
- 请教各位
- 请教各位大大C#中 GetResponseStream()返回什么编码的流。
- 请教各位Android登录空指针问题
- 请教各位Android登录空指针问题
- $.getJSON+js+asp请大神帮看看这样的ASP也返回结果是啥 ASP页面如何编写
- 点击launcher图标后,进入哪个activity的疑惑
- Android动画开始位置问题
- startx命令--Linux命令应用大词典729个命令解读
- android中添加按钮,运行时点击按钮,出现“The application has stopped unexpectedly..."
- 请教各位大大,android访问不了本地服务器
- 文字下方显示下划线,怎么实现下划线长度随文字长度改变?
- 一个菜逼程序员的2016年度总结
- iOS开发 nil,Nil,NULL的区别
- Android相机视频预览左右镜像显示
- Leetcode-203. Remove Linked List Elements
- 用live555+ffmpeg做iOS平台的实时视频播放
- 安卓本地应用需要储存大量数据图片,解决思路应该是?
- tree命令--Linux命令应用大词典729个命令解读