问题描述
您好,我的网站部分描述如下:
Hello, I have a website part described as below:
<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请求,以从客户端发送数据并将其放入表单中.我这样做如下:
I want to make a HTTP POST request to send data from my client and put it into forms.I am doing this as follows:
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代码,但没有成功代码或类似内容.看起来我正在请求网站内容,但未提交表单.知道我在做什么错吗?
The problem is when I read the response I get the HTML code of the site that I am requesting without a success code or anything similar. It looks like I am requesting for site content, but not submitting the form. Any idea what I am doing wrong?
推荐答案
您正在提交到.html
文件.通常,没有将服务器配置为将这些文件视为脚本,这意味着您提交的数据将被简单地忽略和转储.要处理表单提交,您必须提交到专门设计用于处理该提交的脚本或其他程序,例如一个php脚本.
You're submitting to a .html
file. Generally servers aren't configured to treat those files as scripts, which means the data you're submitting is simply ignored and dumped. To handle a form submission, you have to submit to a script or other program specifically designed to handle that submission, e.g. a php script.
这篇关于android HTTP post multipart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!