我有以下内容:
@request.env['RAW_POST_DATA'] = data
@request.env['CONTENT_TYPE'] = 'application/xml'
@request.env['HTTP_CONTENT_TYPE'] = 'application/xml'
post "create", :api_key => api_key, :format => "xml"
Run Code Online (Sandbox Code Playgroud)
test.log 显示了这一点:
Processing ****Controller#create to xml (for 0.0.0.0 at 2011-07-08 15:40:20) [POST]
Parameters: {"format"=>"xml", "action"=>"create", "api_key"=>"the_hatter_wants_to_have_tea1", "controller"=>"****"}
Run Code Online (Sandbox Code Playgroud)
哪个...我想没问题,但是 RAW_POST_DATA 不会在日志中的参数列表中显示为散列...现在...当我使用curl 从终端调用操作时它可以工作:
curl -H 'Content-Type: application/xml' -d '<object><name>Das Object</name></object>' http://notAvailableDuringTesting.butWorksInDevelopmentMode.dev/object.xml?api_key=the_hatter_wants_to_have_tea1
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
我在通过将二进制数据发布到服务器时遇到问题HttpWebRequest。这是我的客户端代码:
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.UserAgent = RequestUserAgent;
request.ContentType = "application/x-www-form-urlencoded";
var responseStr = "";
var dataStr = Convert.ToBase64String(data);
var postData = Encoding.UTF8.GetBytes(
string.Format("uploadid={0}&chunknum={1}&data={2}", uploadId, chunkNum, dataStr));
using (var dataStream = request.GetRequestStream())
{
dataStream.Write(postData, 0, postData.Length);
dataStream.Close();
}
Run Code Online (Sandbox Code Playgroud)
然后我想通过 MVC 控制器处理请求,这是它的签名:
public ActionResult UploadChunk(Guid? uploadID, int? chunkNum, byte[] data)
Run Code Online (Sandbox Code Playgroud)
但我这里有错误,说 data 不是 Base64 编码的数组,我做错了什么?
如何确保异步任务在运行某些任务之前完成。我需要在异步任务更改该变量的值后使用该变量。如果我在异步运行完成之前运行代码,那么我就完蛋了。有什么帮助吗?我显然是异步任务的新手。如果您查看我的代码,我可能没有按照预期使用 onPostExecute() ,因此建议会有所帮助。我最初的想法是继续向异步任务添加东西,但我认为这只是不好的做法,因为我有大量的东西必须串联运行。基本上,我认为它可以归结为:如何确保 UI 线程中的任务在异步任务完成之前不会开始运行。
public class MainActivity extends MapActivity {
myJSONmap;
public void onCreate(Bundle savedInstanceState) {
new AsyncStuff().execute();
locatePlace(myJSONmap);
class AsyncStuff extends AsyncTask<Void, Integer, JSONObject> {
@Override
protected JSONObject doInBackground(Void... params) {
jObject = GooglePlacesStuff.getTheJSON(formatedURL);
return null;
}
@Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
myJSONmap = JSONextractor.getJSONHMArrayL(jObject); // getting the parsed data from the JSON object.
//the arraylist contains a hashmap of all the relevant data from the google website.
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用他们的 Api(https://www.file.io/#one,见下文)在 Excel 中使用 VBA上传https://file.io文件。
我发现这个线程如何将文件上传到 file.io 并获取链接,但是,我不知道如何准确地将它从 C# 传输到 VBA。
File.io 上的语法是:
$ curl -F "file=@test.txt" https://file.io
{"success":true,"key":"2ojE41","link":"https://file.io/2ojE41","expiry":"14 days"}
$ curl https://file.io/2ojE41
This is a test
$ curl https://file.io/2ojE41
{"success":false,"error":404,"message":"Not Found"}
Run Code Online (Sandbox Code Playgroud)
我当前的代码如下所示:
Set objhttp = CreateObject("MSXML2.ServerXMLHTTP")
URL = "https://file.io"
objhttp.Open "post", URL, False
objhttp.setRequestHeader "Content-type", "application/json"
objhttp.Send ("file=@C:/Users/me/Downloads/image.jpg")
Debug.Print objhttp.responsetext
Run Code Online (Sandbox Code Playgroud)
我的响应文本说:
{"success":false,"error":400,"message":"Trouble uploading file"}
Run Code Online (Sandbox Code Playgroud)
我什至不确定路径中的“@”或者是否通常使用标准文件夹等。提前非常感谢!感谢所有帮助。
我知道有很多关于同样问题的问题,但没有一个解决方案对我有用。
我有一个使用 Lumen 内置 API 的 ReactJS 应用程序。该 API 也被React Native和JQuery AJAX 使用,并且在两者上都可以正常工作。
当我尝试从 ReactJS 发送带有 axios的POST请求时,我在OPTIONS请求中收到 405 Method Not Allowed 错误。
axios 请求是:
const body = { username, password };
axios.post(`{$uri}/payment/api/login`, {body})
.then(res => console.log(res))
.catch(err => console.log('Login: ', err));
Run Code Online (Sandbox Code Playgroud)
起初我认为这是一个 CORS 问题,这会很奇怪,因为我的 API 被托管在 AWS S3 上的静态站点使用,没有任何问题。所以我的 CORS 中间件工作正常。
比我尝试使用 fetchAPI 来调用 API 并且工作正常。我尝试从 axios向虚拟 API https://jsonplaceholder.typicode.com/users发送POST请求,并且工作正常。
编辑
好的,所以我刚刚发现 fetchAPI 以application/x-www-form-urlencoded格式发送数据,该格式不受飞行前请求的影响。这应该意味着 CORS 中间件存在问题。
CORSM中间件
<?php …Run Code Online (Sandbox Code Playgroud) 有没有办法指定 swagger 的示例请求?甚至可能是多个?
该Try it out按钮仅显示通用值,例如:
{
"firstName": "string",
"lastName": "string"
}
Run Code Online (Sandbox Code Playgroud)
为了
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当您必须首先编辑所有值时,使用大型对象变得非常困难。我知道我可以使用 Postman,我也可以使用,但是能够使用 swagger创建多个美观且有用的示例会非常好。
我试图了解如何使用 Boost Beast 库处理 HTTP POST 请求的内容。我稍微修改了Boost Beast 高级服务器示例来掌握一些事情。
我已将以下几行添加到示例中的 handle_request() 方法中(就在第 155 行之前):
if ( req.method() == http::verb::post)
{
std::cout << req << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个名为 foobar.dat 的简单测试文件,其中包含以下内容:
This is a test!
Run Code Online (Sandbox Code Playgroud)
我使用以下curl命令将其发送到服务器:
curl -F 'test=@foobar.dat' http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
这会导致服务器输出以下内容:
POST / HTTP/1.1Host: localhost:8080
User-Agent: curl/7.58.0
Accept: */*
Content-Length: 218
Content-Type: multipart/form-data; boundary=------------------------9c747f078ebbe880
--------------------------9c747f078ebbe880
Content-Disposition: form-data; name="test"; filename="foobar.dat"
Content-Type: application/octet-stream
This is a test!
--------------------------9c747f078ebbe880--
Run Code Online (Sandbox Code Playgroud)
所以,我让服务器接收预期的消息。
如果我将测试稍微修改为以下内容,我可以单独提取标头字段以及一个大缓冲区中的正文。
if ( req.method() == http::verb::post)
{
std::cout << "Fields:" << std::endl;
int …Run Code Online (Sandbox Code Playgroud) 我很好奇是否可以在Nest.js 的Request Body 中获取XML 数据。
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
Run Code Online (Sandbox Code Playgroud)
我希望调用一个 HTTP POST API/EPCIS/capture来获取 XML 文档,如下所示:
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epcis:EPCISDocument
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:epcis="urn:epcglobal:epcis:xsd:1"
xmlns:epcglobal="urn:epcglobal:xsd:1"
xsi:schemaLocation="urn:epcglobal:epcis:xsd:1 EPCglobal-epcis-1_0.xsd"
creationDate="2008-03-16T22:13:16.397+01:00"
schemaVersion="1.0">
<EPCISBody>
<EventList>
<ObjectEvent>
<eventTime>2008-03-16T22:13:16.397+01:00</eventTime>
<eventTimeZoneOffset>+01:00</eventTimeZoneOffset>
<epcList>
<epc>urn:epc:id:sgtin:0614141.107346.2017</epc>
<epc>urn:epc:id:sgtin:0614141.107346.2018</epc>
</epcList>
<action>OBSERVE</action>
<bizStep>urn:epcglobal:epcis:bizstep:fmcg:shipped</bizStep>
<disposition>urn:epcglobal:epcis:disp:fmcg:unknown</disposition>
<readPoint>
<id>urn:epc:id:sgln:0614141.07346.1234</id>
</readPoint>
<bizLocation>
<id>urn:epcglobal:fmcg:loc:0614141073467.A23-49</id>
</bizLocation>
<bizTransactionList>
<bizTransaction type="urn:epcglobal:fmcg:btt:po">
http://transaction.acme.com/po/12345678
</bizTransaction>
</bizTransactionList>
</ObjectEvent>
</EventList>
</EPCISBody>
</epcis:EPCISDocument>
Run Code Online (Sandbox Code Playgroud)
但我得到的只是{}在记录传入的请求正文时。我的邮递员设置已经提到:
Content-Type: application/xml
并在Body我粘贴了上面提到的 …
我有一个 POST FastAPI 方法。我不想构造类或查询字符串。所以,我决定应用Body()方法。
@app.post("/test-single-int")
async def test_single_int(
t: int = Body(...)
):
pass
Run Code Online (Sandbox Code Playgroud)
这是请求
POST http://localhost:8000/test-single-int/
{
"t": 10
}
Run Code Online (Sandbox Code Playgroud)
这是回应
HTTP/1.1 422 Unprocessable Entity
date: Fri, 22 May 2020 10:00:16 GMT
server: uvicorn
content-length: 83
content-type: application/json
connection: close
{
"detail": [
{
"loc": [
"body",
"s"
],
"msg": "str type expected",
"type": "type_error.str"
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是,在尝试了许多样本后,我发现如果我有多个Body(). 例如,
POST http://localhost:8000/test-single-int/
{
"t": 10
}
Run Code Online (Sandbox Code Playgroud)
要求
POST http://localhost:8000/test-multi-mix/
{
"s": "test",
"t": 10
} …Run Code Online (Sandbox Code Playgroud) 我尝试使用盈透证券客户端门户 Web API:
例如,我尝试更新当前选择的帐户:
// it is need for change User-Agent as recommended*
chrome.webRequest.onBeforeSendHeaders.addListener(function (details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'User-Agent') {
details.requestHeaders[i].value = 'Console';
break;
}
}
return {requestHeaders: details.requestHeaders};
}, {urls: ['<all_urls>']}, ['blocking', 'requestHeaders']);
// it is code of make of POST request
var data = {};
data['acctId'] = 'U1234567';
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://localhost:5000/v1/portal/iserver/account', true);
xhr.setRequestHeader('Content-Type', 'application/json'); …Run Code Online (Sandbox Code Playgroud)