我有以下 HTML 代码
<%@ Page Language="C#" %>
<html>
<head>
<title></title>
</head>
<body>
<form id="frmSystem" method="post" action="target.aspx">
<input id="txtTextField" type="text" />
<input id="btnPost" value="Submit" onclick="javascript:frmSystem.submit();" type="button" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
目标页面即将出现,但它正在接收的表单是空的。我的 target.aspx 页面上有一个断点,虽然我可以看到一个表单,但它的键是空的,Request["txtTextField"] 什么也没给我。
任何线索为什么?
我正在尝试使用 Go 包 mime/multipart 和 http 发送多部分表单,我需要一些帮助来解决它。
HTML 将是:
<html>
<head><title>Multipart Test</title></head>
<body>
<form action="/multipart" enctype="multipart/form-data" method="POST">
<label for="file"> Please select a File </label>
<input id="file" type="file" name="file"/>
<br>
<label for="input1"> Please write some text </label>
<input id="input1" type="text" name="input1"/>
<br>
<label for="input2"> Please write some more text </label>
<input id="input2" type="text" name="input2"/>
<br>
<input type="submit" name="Submit" value="Submit"/>
</body>
Run Code Online (Sandbox Code Playgroud)
我的 Go 方法是这样的:
var buffer bytes.Buffer
w := multipart.NewWriter(&buffer)
// Write fields and files
w.CreateFormField("input1")
w.WriteField("input1","value1")
w.CreateFormFile("file","filename.dat")
// I need a …Run Code Online (Sandbox Code Playgroud) 简而言之,我有一个网站,您可以在其中注册为用户并添加数据。目前只添加一次特定数据才有意义,因此添加应该是幂等的,但理论上您可以多次添加相同的数据。我不会在这里讨论。
根据RFC 2616,GET 请求应该是幂等的(真的是无效的)。我希望用户能够执行诸如访问之类的操作
http://example.com/<username>/add/?data=1
Run Code Online (Sandbox Code Playgroud)
这将添加该数据。让 PUT 请求使用 REST 来执行此操作是有意义的,但我不知道如何使用浏览器发出 PUT 请求,而且我非常怀疑大多数人是否愿意或愿意打扰。即使使用 POST 也是合适的,但这也有类似的问题。
是否有一些技术上正确的方法允许用户仅使用 GET 添加数据(例如,通过手动访问链接,或允许外部网站使用链接)。当他们访问此页面时,我可以使用 javascript 或 cURL 发出自己的 POST/PUT 请求,但这似乎仍然违反了幂等 GET 请求的精神。
我已经看到了与此略有关系的问题,但没有一个能解决我的问题.我已经设置了Ext.Ajax.request,如下所示:
var paramsStringVar = 'param1=1¶m2=two¶m3=something¶m4=etc';
Ext.Ajax.request({
url: '/cgi-bin/url.pl',
method:'POST',
params:paramsStringVar,
timeout:120000,
success: function(response, opts){
var objhtml = response.responseText; //content returned from server side
console.log(objhtml);
}
});
Run Code Online (Sandbox Code Playgroud)
此请求从后端检索适当的内容.一个参数是outputType,它可以取值{html,excel,csv}.当返回html进行显示时,我能够正确处理和显示它.现在问题......
当我将outputType参数设置为csv或excel时,我会根据请求将相应的内容作为csv或tsv(excel)返回.但是,我不想要内容,我想提示下载文件(csv或excel).如何让浏览器自动提示用户下载文件而不是仅仅检索extjs中的文本内容?
版本4.07所以我不能使用任何4.1唯一的功能
我想发送一个压缩的请求正文作为基于Web服务的应用程序的POST http请求.任何人都可以帮助我如何发送压缩的http请求或如何发送压缩请求正文作为POST http请求的一部分?
编辑:在此处添加解决方案
HttpURLConnection request = null;
StringBuilder sb = new StringBuilder(getFileAsString("TestFile.txt"));
String fileStr = getFileAsString("TestFile.txt");
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope(hostip, port),
new UsernamePasswordCredentials("username", "password"));
PutMethod post = new PutMethod(url);
post.setRequestHeader("Content-Encoding", "gzip")
Run Code Online (Sandbox Code Playgroud) 我能够使用缓冲区处理程序获取表单数据,但它是一个空函数,我无法返回表单数据值。总共有大约 4-7 个表单,我不想最终一遍又一遍地编写相同的处理程序,因为默认函数是无效的。
html:
<!DOCTYPE html>
<html>
<head><title>Login Page</title></head>
<body>
<a href="/activateUserPage">activate user</a>
<br/>
<a href="/login">log in</a>
<br/>
<form id='login' action='/login' method='post'>
<fieldset >
<legend>Login</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for='username' >UserName: </label>
<input type='text' name='username' id='username' maxlength="50"/>
<label for='password' >Password: </label>
<input type='password' name='password' id='password' maxlength="50"/>
<input type='submit' name='Submit' value='Submit' />
</fieldset>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
爪哇:
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpServer;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;
import org.vertx.java.deploy.Verticle;
import java.util.Collection;
import java.util.List;
import java.util.Map; …Run Code Online (Sandbox Code Playgroud) 我已经设置了几乎所有的数据:
String capcha = editText.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl.asp");
// Add your data
String str = "param1=x¶m2=y";
StringEntity strEntity = new StringEntity(str);
httppost.setEntity(strEntity);
httppost.setHeader("Set-Cookie", sessionCookie);
httppost.setHeader("Accept", "text/html");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
// httppost.setHeader("Content-Length", ); HOW TO GET CONTENT LENGTH ?
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
我在一个简单的Spring Boot应用程序中有一个Thymeleaf模板.该模板在表中包含一个列表,如下所示:
<p>There are <span th:text="${#lists.size(persons)}"></span> people:</p>
<table th:if="${not #lists.isEmpty(persons)}" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Telephone</th>
<th>Email</th>
<th>Actions</th>
</tr>
<tr th:each="person : ${persons}">
<td th:text="${person.personId}"></td>
<td th:text="${person.name}"></td>
<td th:text="${person.address}"></td>
<td th:text="${person.telephone}"></td>
<td th:text="${person.email}"></td>
<td>
<a href="#" data-th-href="@{/edit(personId=${person.personId})}">Edit</a> |
<a href="#" data-th-href="@{/delete(personId=${person.personId})}">Delete</a>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我想根据表格中的最后一个单元格启用编辑和删除功能.但目前这两个请求都是针对HTTP GET的.这对于从服务器获取人员的详细信息以进行编辑的编辑很好,但是由于服务器上的数据更改,删除应该触发POST请求.
有没有人知道Thymeleaf是否允许每行一个表的POST请求?或者我是否必须每行编写一个简单的HTML表单?
GET表格目前是:
<td>
<a href="#" data-th-href="@{/edit(personId=${person.personId})}">Edit</a>
<!--a href="#" data-th-href="@{/delete(personId=${person.personId})}">Delete</a></td-->
<form method="get" th:action="@{/edit(personId=${person.personId})}">
<button type="submit" name="submit" value="value">Edit</button>
</form>
</td>
Run Code Online (Sandbox Code Playgroud)
我有一个链接和一个表格进行测试.
要调用的控制器方法是:
// Gets a Person.
@RequestMapping(value="/edit", method=RequestMethod.GET)
public String getEditPerson(@RequestParam("personId") String personId, Model model) { …Run Code Online (Sandbox Code Playgroud) 我可以从浏览器输入此URL,输入凭据后,它会成功调用我的API http://172.16.0.40/rest/vars/set/1/12/666。
我正在尝试使用HTTPClient从ESP8266进行此操作。我的凭据是username:password,我使用了一个在线转换实用程序来获取dXNlcm5hbWU6cGFzc3dvcmQ =。
当执行时,以下返回错误701(不知道那是什么)。
HTTPClient http;
http.begin("172.16.0.40", 80, "/");
http.addHeader("Content-Type", "text/plain");
http.addHeader("Authorization", "dXNlcm5hbWU6cGFzc3dvcmQ=");
auto httpCode = http.POST("rest/vars/set/1/12/999");
Run Code Online (Sandbox Code Playgroud)
如果我注释掉Authorization标头,则会得到401,这是未经授权的访问。我究竟做错了什么?
我是android的新手,我不知道如何使用改造过帐
我有自己的服务器,可以将数据返回给我,我需要获取其中一个
我必须发送由edittext占用的“城市名称”,并将其传递到“ ms_data's”关键字(即keyword =“ India”)内
到目前为止,这是我尝试过的...
改造建造者类
public class RetrofitBuilder {
public static Retrofit retrofit;
public static final String BASE_URL = "my url";
public static Retrofit getApiData()
{
if(retrofit==null)
{
retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create()).build();
}
return retrofit;
}
}
Run Code Online (Sandbox Code Playgroud)
POJO课
public class MessageFromServer {
private String city_name;
public MessageFromServer(String city_name) {
this.city_name = city_name;
}
public String getCity_name() {
return city_name;
}
public void setCity_name(String city_name) {
this.city_name = city_name;
}
@Override
public boolean equals(Object o) { …Run Code Online (Sandbox Code Playgroud)