java匹配<!doctype html>,java.net.ProtocolException:意外的状态行:

我是Java和Android编程的新手,我试图在服务器上获取PHP文件的结果,但出现以下异常:

java.net.ProtocolException: Unexpected status line:

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.http.StatusLine.parse(StatusLine.java:54)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:905)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:789)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:443)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:388)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:231)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at it.codesnippet.dots.LoginActivity$1$override.run(LoginActivity.java:49)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at it.codesnippet.dots.LoginActivity$1$override.access$dispatch(LoginActivity.java)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at it.codesnippet.dots.LoginActivity$1.run(LoginActivity.java:0)

07-10 11:18:54.112 24683-25081/it.codesnippet.dots W/System.err: at java.lang.Thread.run(Thread.java:818)这是异常来自的代码(在LoginActivity.java中):

Thread loginCheckThread = new Thread(new Runnable() {

public void run() {

String result = "", dataObj = "";

TextView username = (TextView) findViewById(R.id.login_mail);

TextView password = (TextView) findViewById(R.id.login_password);

JSONObject jsonObj = new JSONObject();

try {

jsonObj.put("loginMail", username.getText());

jsonObj.put("loginPassword", password.getText());

dataObj = jsonObj.toString(0);

} catch (JSONException e) {

e.printStackTrace();

}

try {

URL url = new URL("http://myserver.it/testandroid.php?data=" + dataObj);

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

try {

/* line #49 */ InputStream in = new BufferedInputStream(urlConnection.getInputStream());

ByteArrayOutputStream bo = new ByteArrayOutputStream();

int i = in.read();

while (i != -1) {

bo.write(i);

i = in.read();

}

result = bo.toString();

} catch (IOException e) {

result = "Exception: Class::IOStream Related";

e.printStackTrace();

} finally {

urlConnection.disconnect();

}

} catch (IOException e) {

result = "Exception: Class::URL Related";

}

System.out.println(result);

}

});

loginCheckThread.start();导致异常的行是#49行:

InputStream in = new BufferedInputStream(urlConnection.getInputStream());PHP文件现在只是一个测试文件,应该返回从查询字符串中的data变量中检索到的 - :

$jsonObj = json_decode($_GET["data"], TRUE);

echo $jsonObj["loginMail"] . " - " . $jsonObj["loginPassword"];大约两天这个问题阻止了我,我能做些什么来解决这个问题?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值