我遇到的情况是,我正在努力解决现实世界中的 REst GET 和 POST 架构哲学。
我有一个本质上是幂等的 REst 调用。它需要在其有效负载中包含复杂的数据类型(XML 中的保险单),对其执行复杂的业务逻辑并返回保费。它对状态没有任何作用,因此本质上是幂等的。
REst 调用目前是 POST。这样做的有效理由是消息正文很大,很可能会被丢弃并在 Internet Explorer 中变得混乱。然而,它也是幂等的,并且从根本上违反了 GET 与 POST 的原则。
以前有人遇到过这个难题吗?谢谢。
HTTP 协议提供了哪些可能性来将数据和参数从客户端传输到服务器?
Content-TypeHTTP 正文,其内容类型通过标头参数(FormParams 和任何其他发布数据)定义这是正确和完整的吗?
首先,我对 HTTP 命令和 libcurl 库非常陌生,所以我很可能不理解一些基本的东西。也就是说,我正在尝试在基于 Windows 的 MFC 应用程序上复制通过内部服务器发送到设备的 HTTP POST 命令。本质上,我正在发送一个小位图图像和一个命令。我使用 Fiddler 捕获了该命令,它看起来像:
POST /Service/MyCommand HTTP/1.1
Authorization: MyAuth
Content-Type: image/bmp
User-Agent: Mozilla/4.0 (Windows 7 6.1) Java/1.7.0_51
Host: MyHost:MyPort
Accept: MyAccept
Connection: MyConnection
Content-Length: 15606
/* BMP Data */
Run Code Online (Sandbox Code Playgroud)
我在复制这个(使用 libcurl)时遇到两个问题。首先,我的“Service/MyCommand”后命令出现在标头的最末尾,而不是“POST /”之后。我尝试移动它,但它将不再出现在我的 WireShark 过滤器窗口中。其次,当我尝试将内容长度设置为 15606 时,与原始长度一样,WireShark 上的协议从“POST”切换为“TCP”。我附上了下面的代码。
int CHttpPost::fnSendContent()
{
using namespace std;
int Error = 0;
CString str;
CURL* curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "a"; // not …Run Code Online (Sandbox Code Playgroud) 我正在android中向 Url https://nitos.gr发出 Http POST 请求。
该url没有域名。Stackoverflow 不允许我在文本中包含带有数字的 URL,因此我只是编写一个随机 URL https://nitos.gr来作为示例。
我收到400 响应代码,并打印 getErrorStream() 给出 libcore.net.http.UnknownLengthHttpInputStream@41eba330
但是,我成功执行了 HTTP GET 请求。url 是https,因此我有一个允许所有 SSL 连接的假信任管理器。
总之:
协议: HTTPS
GET请求:成功
POST 请求:失败
请求代码: 400
错误消息: java.io.FileNotFoundException: https: //nitos.gr
错误流: java.io.FileNotFoundException: https: //nitos.gr
执行 POST 请求的方法如下:
public void setTestbedData(String path, String data) {
HttpURLConnection con = null;
try {
con = (HttpURLConnection) ( new URL(Constants.BASE_URL + path)).openConnection();
// If you invoke …Run Code Online (Sandbox Code Playgroud) android filenotfoundexception http-post httpurlconnection http-status-code-400
我有一组数据:
var myArray = [{"id": 1, "name", "John"},{"id": 2, "name", "Joe"},{"id": 3, "name", "Bill"}]
$.post("/MyController/Update", myArray, function (data) {
alert("Complete");
});
Run Code Online (Sandbox Code Playgroud)
这是我的 asp.net-mvc 控制器操作
public ActionResult Update(List<Person> people)
{
return Json(new {Success = true});
}
public class Person
{
public int id {get;set;}
public string name {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
var paramString = JSON.stringify({ people: myArray});
$.post("/MyController/Update", paramString , function (data) {
alert("Complete");
});
Run Code Online (Sandbox Code Playgroud)
但是当我查看服务器上的 people 参数时,我要么看到:
关于我在这里做错了什么有什么建议吗?
问题:尝试将讲师的python 2代码翻译为python 3
具体问题:无法从 python 3 中的表单访问消息字段
def do_POST(self):
try:
self.send_response(301)
self.send_header('Content-type', 'text/html')
self.end_headers()
ctype, pdict = cgi.parse_header(
self.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
fields = cgi.parse_multipart(self.rfile, pdict)
messagecontent = fields.get('message')
output = ""
output += "<html><body>"
output += " <h2> Okay, how about this: </h2>"
output += "<h1> %s </h1>" % messagecontent[0]
output += '''<form method='POST' enctype='multipart/form-data' action='/hello'><h2>What would you like me to say?</h2><input name="message" type="text" ><input type="submit" value="Submit"> </form>'''
output += …Run Code Online (Sandbox Code Playgroud) 我正在使用 Postman v4.9.3,我正在尝试使用 POST 请求查看页面响应。问题是,当单击“预览”按钮时,未加载外部 CSS。有人可以帮我解决吗?或者是否有其他方法使用 POST 请求页面并设置一些标头,然后渲染返回的页面?
------更新 能够使用 UsernamePasswordCredentials 类修复它 代码如下所示 val client = new DefaultHttpClient client.getCredentialsProvider().setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("user","password") );
我正在尝试对 Restful API 进行 HttpPost 调用,它需要用户名/密码,如何传递这些参数?我尝试了2种方法
post.addHeader("Username","user")
post.addHeader("Password","clear pwd")
and
post.addHeader("Authorization","Basic base64encoded username:password")
Run Code Online (Sandbox Code Playgroud)
没有任何作用,我得到的响应文本为
响应文本 = HTTP/1.1 401 未经授权 [WWW-Authenticate:摘要领域 =“API 领域”,域 =“/default-api”,nonce =“pOxqalJKm5L5QXiphgFNmrtaJsh + gU”,算法 = MD5,qop =“auth”,陈旧 = true,内容类型:text/html;字符集 = ISO-8859-1,缓存控制:必须重新验证,无缓存,无存储,内容长度:311] org.apache.http.conn.BasicManagedEntity@5afa04c
下面是我的代码
val url = "http://restapi_url";
val post = new HttpPost(url)
//post.addHeader("Authorization","Basic QWBX3VzZXI6Q0NBQGRidHMxMjM=")
post.addHeader("Username","user_user")
post.addHeader("Password","clear pwd")
post.addHeader("APPLICATION_NAME","DO")
val fileContents = Source.fromFile("input.xml").getLines.mkString
post.setHeader("Content-type", "application/xml")
post.setEntity(new StringEntity(fileContents))
val response = (new DefaultHttpClient).execute(post)
println("Response Text = "+response.toString()) …Run Code Online (Sandbox Code Playgroud) 我可以创建多个具有相同请求映射和不同请求正文的 HTTP POST 方法吗
@RequestMapping("api/v1/")
@RequestMapping(value = "test" ,method = RequestMethod.POST)
public RObjet create(@RequestBody RBody rbody)
{
// do some process...
}
@RequestMapping("api/v1/")
@RequestMapping(value = "test" ,method = RequestMethod.POST)
public RObjet2 create2(@RequestBody RBody2 rbody)
{
// do something.
}
Run Code Online (Sandbox Code Playgroud)
这可能吗。?我们如何在 Spring Boot 中处理这个问题。
我正在使用一个名为Slim 的库将图像上传到我的 asp.net MVC 项目。
JQuery 库使用 XMLHttpRequest 向服务器发送请求,我已经阅读了所有手册,但没有任何关于如何将防伪造令牌包含到服务器的内容。
所以我在发送之前手动添加了这一行:
data.__RequestVerificationToken = $('input[name="__RequestVerificationToken"]').val();
Run Code Online (Sandbox Code Playgroud)
即使令牌包含在数据中,Asp.net MVC 过滤器:ValidateJsonAntiForgeryTokenAttribute也无法识别它,因为它期望令牌位于 header中。这是服务器上的验证代码:
AntiForgery.Validate(cookie != null ? cookie.Value : null,
httpContext.Request.Headers["__RequestVerificationToken"]);
Run Code Online (Sandbox Code Playgroud)
这是库的发送函数,其中包含我在底部添加的额外行以包含令牌。如何将令牌包含在标头中?
var send = function send(url, data, requestDecorator, progress, success, err) {
var xhr = new XMLHttpRequest();
// if progress callback defined handle progress events
if (progress) {
xhr.upload.addEventListener('progress', function (e) {
progress(e.loaded, e.total);
});
}
// open the request
xhr.open('POST', url, true);
// if request decorator defined pass …Run Code Online (Sandbox Code Playgroud) http-post ×10
http ×2
http-get ×2
jquery ×2
ajax ×1
android ×1
architecture ×1
asp.net-mvc ×1
c++ ×1
forms ×1
html ×1
http-headers ×1
java ×1
javascript ×1
libcurl ×1
postman ×1
protocols ×1
python ×1
python-2.7 ×1
python-3.x ×1
rest ×1
scala ×1
spring-boot ×1