android 请求权限失败怎么办,java – Android HTTP POST请求错误 – 套接字失败EACCES(权限被拒绝)...

我正在尝试从

Eclipse下的Android应用程序向我的localhost发送POST请求,但是我收到此错误:

socket Failed EACCES (Permission denied).

我是通过apache.commons库做的.我之前试过通过HttpClient连接,但是也有类似的错误:

Connect to myhost refused.

这是代码:

public void onClick(View v) {

login = (EditText) findViewById(R.id.entry_login);

userLogin = login.getText().toString();

pwd = (EditText) findViewById(R.id.entry_password);

userPwd = pwd.getText().toString();

BufferedReader br = null;

HttpClient httpclient = new HttpClient();

PostMethod method = new PostMethod("http://127.0.0.1/testPost.PHP");

method.addParameter("name","Arthur");

System.out.println("Login: " + userLogin);

try {

httpclient.executeMethod(method);

int returnCode = httpclient.executeMethod(method);

if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {

System.err.println("The Post method is not implemented by this URI");

// Still consume the response body

method.getResponseBodyAsString();

}

else {

br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));

String readLine;

while (((readLine = br.readLine()) != null)) {

System.err.println(readLine);

}

}

/* List nameValuePairs = new ArrayList(2);

nameValuePairs.add(new BasicNameValuePair("name","Arthur"));

nameValuePairs.add(new BasicNameValuePair("OP_ID","10001"));

nameValuePairs.add(new BasicNameValuePair("IP_ADDRESS","127.0.0.1"));

nameValuePairs.add(new BasicNameValuePair("FIELDS=field100",userLogin + "&field101=" + userPwd));

nameValuePairs.add(new BasicNameValuePair("REQ_TYPE=","26"));

*/

System.out.println("http connection done well!");

// response.getStatusLine();

}

catch (Exception e) {

System.out.println(e.getMessage());

}

finally {

method.releaseConnection();

if (br != null)

try {

br.close();

}

catch (Exception fe) {

}

}

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值