你好,我有一个网站部分描述如下:
<div id="insertA">
<form class="MultiFile-intercepted" enctype="multipart/form-data"
method="post" onsubmit="return checkAnomalyFields();"
action="dodajN.html">
<table style="border-weight: 0px">
<tbody>
<tr>
<tr>
<td id="wybory"><select id="typ" onchange="typeSelected()" size="1"
name="typuId">
</td>
<td>
</tr>
<tr>
<td>Szerokość: <input id="szer" type="text" onchange="setMarker()"
value="" name="szer">
<div id="szerErr" class="err">Proszę podać szerokość na terenie
Polski (49-55).</div>
</td>
<td>Długość: <input id="dlug" type="text" onchange="setMarker()"
value="" name="dlug">
<div id="dlugErr" class="err">Proszę podać długość na terenie
Polski (14-25).</div> <input id="id" type="hidden" value=""
name="id">
</td>
</tr>我想发出一个HTTP POST请求,以便从客户端发送数据并将其放入表单中。我这样做的方法如下:
try {
HttpClient client = new MyHttpClient(Send.this);
String postURL = "url";
HttpPost post = new HttpPost(postURL);
//FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//reqEntity.addPart("myFile", bin);
reqEntity.addPart("typuId", new StringBody("1"));
reqEntity.addPart("statusuId", new StringBody("2"));
reqEntity.addPart("szer", new StringBody("52.321911"));
reqEntity.addPart("dlug", new StringBody("19.464111000000003"));
reqEntity.addPart("opis", new StringBody("jakis opis"));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
AlertDialog.Builder alert=new AlertDialog.Builder(Send.this);
alert.setTitle("Niepoprawne dane").setMessage(EntityUtils.toString(resEntity)).setNeutralButton("OK", null).show();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}问题是,当我读取响应时,我得到的是我请求的站点的HTML代码,但没有成功代码或任何类似的代码。看起来我是在请求站点内容,而不是提交表单。你知道我做错了什么吗?
发布于 2012-10-23 22:31:55
您正在提交到.html文件。通常,服务器不会被配置为将这些文件视为脚本,这意味着您提交的数据将被忽略并转储。为了处理表单提交,你必须提交给一个脚本或者其他专门设计来处理表单提交的程序,例如php脚本。
发布于 2012-10-24 03:38:35
好的,为了澄清Marc B所说的:action="dodajN.html"几乎肯定是错的。我从来没有见过能让你做到这一点的web服务器(当然,任何事情都是可能的)。它可能应该是action="cgi-bin/something"或类似的东西。
然而,这实际上并不那么重要,因为你的应用程序并没有使用action子句,而是写到"url“,这是更错误的。如果你能告诉我们你真正写的是什么url,可能会有所帮助。
但最终,您调试它的方法是查看服务器日志,看看在那一端发生了什么。
一般来说,当我开发这样的东西时,我首先编写服务器端cgi脚本和一个使用它的网页。一旦我的API处理完网页,我才开始尝试从Android应用程序调用cgi脚本。
我的调试过程包括: 1)读取服务器日志。2)让我的cgi脚本编写自己的调试日志。3)让我的android应用程序将响应代码和头文件转储到logcat。
https://stackoverflow.com/questions/13032736
复制相似问题