感谢您的时间我有一个POST请求,我想在蓝图养蜂场中记录,标题是这样的:
text/html的
_method:POST
数据[用户] [用户名]:
数据[用户] [口令]:
数据[用户] [记住]:0
我有类似的东西,但我不知道如何完成它:
## login [/users/login/{username}{password}{remember}{ident}]
Login with a user and password
+ Parameters
+ username (required, string, `myname`) ... the username format should follow CakePHP: data[User][username].
+ password (required, string, `whatever`) ... the password format should follow CakePHP: data[User][password]
+ remember (required, number, `0`) ... the remember format should follow CakePHP: data[User][remember]
+ ident (optional, number, `0`) ... the ident format should follow CakePHP: data[User][ident]
### make login [POST]
+ login …Run Code Online (Sandbox Code Playgroud) 我有一段客户端代码,可以从Google云端硬盘导出.docx文件并将数据发送到我的服务器.它非常简单,它只是导出文件,使其成为blob,并将blob发送到POST端点.
gapi.client.drive.files.export({
fileId: file_id,
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}).then(function (response) {
// the zip file data is now in response.body
var blob = new Blob([response.body], {type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"});
// send the blob to the server to extract
var request = new XMLHttpRequest();
request.open('POST', 'return-xml.php', true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onload = function() {
// the extracted data is in the request.responseText
// do something with it
};
request.send(blob);
});
Run Code Online (Sandbox Code Playgroud)
这是我的服务器端代码,用于将此文件保存到我的服务器上,以便我可以使用它来执行操作:
<?php
file_put_contents('tmp/document.docx', fopen('php://input', 'r'));
Run Code Online (Sandbox Code Playgroud)
当我运行它时,该文件在我的服务器上创建.但是,我认为它已损坏,因为当我尝试解压缩它时(就像你可以用.docx做的那样),会发生这种情况:
$ mv tmp/document.docx tmp/document.zip
$ unzip tmp/document.zip
Archive: document.zip
error …Run Code Online (Sandbox Code Playgroud) 我正在使用带有带有属性值的html表单的POST方法和curl命令。我正在使用flask框架。我的内容类型不是application-json。
我在标头中给出的命令如下:
curl -b cookies.txt -F "description=description" -F "file_name=@curl_commands.md" -X POST http://localhost:5000/api/v1.0/upload_doc
-H 'workflow_id:1' -H 'change_workflow:Y'
Run Code Online (Sandbox Code Playgroud)
我应该为Content-type指定什么?这是js ajax调用所必需的。
如果我有一个POST参数
d={"data": "<span>hello</span>"}
Run Code Online (Sandbox Code Playgroud)
这是一个JSON字符串,它工作正常,request.POST.get('d')包含完整的字符串.但如果我把它改成
d = {"data": "<span>hel;lo</span>"}
print (request.POST.get('d')) #prints '{"data": "<span>hel'
Run Code Online (Sandbox Code Playgroud)
出于某种原因,分号后的任何内容都被切断了.我可以确认这不是Javascript这样做,因为我曾经使用完全相同的javascript代码发布到能够检索数据的PHP API.自从迁移到Python和webapp2以来,我遇到了这个问题.
简而言之,我想将图像的二进制数据发送到我的处理程序,该处理程序将作为字节数组保存在DB中.使用readAsBinaryString(f)我的Javascript 读取文件输入的值,我会得到如下输出:
GIF89a,úæÿÿÿ2c½3fÌ Smaäµééúþc«T.[ÈéùAtεÚõ[ãX߯î*[µc³8Ûõüÿfj¥æ§ÈïÛå÷ËØñI}ÓQ×
*\»q£E}Ûÿå§ÓõþÿIÛv¤Þ´Åè«æ ³][us¬çAy×MÞ,a½«ÔóZÝL2äëùQ×(Eq<pË5V¨·ÏIÓ¨»åQßY¥3bØÈ
æ¬z³é<uÓ3£ÎñE¾á÷RÛR¢K®ÎØØìÍAtÓÑÔØrÀ-hݪÑïôõüR|ÎäóÖUËåæçXÔw»^s®ëI}ÛQ}ÔEÛ·Îñ½Óêd»Ì
ÌëöåóôöÖàñE×Cr¿C¤3óúëLÍYÜ3fõûöÑðû Øûÿõw²ñ`ª»ßÀy|Á¿ÃIuÔM×ûñû{¹R4¼ìe¡äl«ç!ÿNETSCA
PE2.0!ÿXMP DataXMP<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpm
eta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02
/06-14:56:27 // etc..
Run Code Online (Sandbox Code Playgroud)
该数据通过AJAX发送:
$.ajax({
url: theUrl,
type: 'POST',
data: { Image: image } // image = data above
});
Run Code Online (Sandbox Code Playgroud)
这是二进制字符串?当我将此字符串发送到我的处理程序(IHttpHandler)时,为了将其存储到字节数组中,如果我将编码设置为ISO-8859-1,我可能只获取字节.
public void ProcessRequest (HttpContext aContext)
{
// This works as long as requestValidationMode = "2.0" in web.config
// Is there a way to bypass HttpRequestValidationException just on
// THIS data?
byte[] imageBytes = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(_Context.Request["Image"]);
//... …Run Code Online (Sandbox Code Playgroud) 在C#上,我正在打印我发送到控制台的JSONified字符串,它的内容为
{ "message" : "done", "numSlides" : 1, "slides" : [{ "num" : 1, "key" : "530d8aa855df0c2d269a5a5853a47a469c
52c9d83a2d71d9/1slide/Slide1_v8.PNG" }], "bucket" : "xx.xxxxxxxxxx", "error"
: null, "wedge" : false, "tenant" : null, "name" : null }
Run Code Online (Sandbox Code Playgroud)
然后我这样做将它转换为字节数组并发送它
WebRequest request = WebRequest.Create(Program.api +"/"+ route);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//Get the request stream
Stream dataStream = request.GetRequestStream();
byte[] byteArray = Encoding.UTF8.GetBytes(myString);
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
Run Code Online (Sandbox Code Playgroud)
在node.js方面,我在console.logging res.body时得到这个:
{ '{ "message" : "done", "numSlides" : 1, "slides" : ': { '{ "num" …Run Code Online (Sandbox Code Playgroud) 我有一个非常基本的问题:
multipart/form-data和 和有application-x-www-form-urlencoded什么区别?
数据传输是如何在这两者中进行的?
而且,我们可以在同一个请求中使用两者吗?
我试图通过Excel VBA自动将文件加载到网站,但我正在努力与网页的文件加载部分正确交互.我已经阅读了许多不同的网页,并在这里和其他来源上解答如何做到这一点,但到目前为止我的尝试都失败了.
不可否认,我并不是真的通过VBA和各种HTML(或其他)元素与IE进行交互,需要一些帮助.
我正在努力与之互动的网页部分是这样的:
<LABEL ACCESSKEY=U CLASS=filelabel>Upload a file to current older:
<INPUT TYPE="file" NAME="eftupload" CLASS=filefield/></LABEL>
<INPUT TYPE="submit" value="Upload" CLASS=submitbutton>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我设法编写的VBA如下(我知道有点乱,因为我仍在以各种方式使其工作)我试图使用的web元素位于"我的URL 2":
Sub File2Web()
'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer
'make IE browser visible (False would allow …Run Code Online (Sandbox Code Playgroud) 当我想上传文件时,我正在处理需要此请求类型的站点的 REST API:
所以我做了这个代码:
import requests
url = 'http://httpbin.org/post'
parameters = {
'format': 'pdf',
}
headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
'Authorization' : 'Some authorization code'
}
data = {'file': open('1.pdf', 'rb')}
r = requests.post(url, params=parameters, headers=headers, data=data)
print(r.text)
Run Code Online (Sandbox Code Playgroud)
但似乎请求正在丢弃数据:
{
"args": {
"format": "pdf"
},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Some authorization code",
"Connection": "close",
"Content-Length": "30",
"Content-Type": "multipart/form-data",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.1"
}, …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的服务,它调用URL并捕获由该服务写出的状态;
// Service call used to determine availability
System.Net.WebClient client = new System.Net.WebClient();
// I need this one (sorry, cannot disclose the actual URL)
Console.WriteLine(client.DownloadString(myServiceURL + ";ping"));
// I added this for test purposes
Console.WriteLine(client.DownloadString("https://www.google.com"));
Run Code Online (Sandbox Code Playgroud)
myServiceURL行的"DownloadString"引发错误"底层连接已关闭:发生了意外错误",Fiddler中没有显示此行,而google.com的"DownloadString"工作正常,我看到控制台输出.
根据错误的其他建议,我尝试了设置UseDefaultCredentials,编码选项,为请求添加适当的标头的组合,这些都没有任何区别.
client.UseDefaultCredentials = true;
client.Encoding = Encoding.UTF8;
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中导航到myServiceURL时,它正常工作,并按预期显示"OK".
来自同一服务的另一种方法编码如下:
// Request
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(myServiceURL + ";login");
// Set the request configuration options
req.Method = "POST";
req.ContentType = "text/xml";
req.ContentLength = bytes.Length;
req.Timeout = -1;
// Call for the request stream
using (Stream os …Run Code Online (Sandbox Code Playgroud) c# ×3
javascript ×3
python ×3
ajax ×1
android ×1
apiary.io ×1
apiblueprint ×1
asp.net ×1
bytearray ×1
curl ×1
docx ×1
excel ×1
excel-vba ×1
flask ×1
html ×1
http ×1
java ×1
json ×1
node.js ×1
php ×1
post ×1
python-2.7 ×1
rest ×1
vba ×1
web-services ×1
webapp2 ×1
webclient ×1
webrequest ×1
zip ×1