postman POST请求返回400错误请求

kuarbcqp  于 2022-11-07  发布在  Postman
关注(0)|答案(1)|浏览(159)

我有一个问题与POST请求到服务器。感谢基本的认证我设法认证,但请求仍然返回400坏请求。你知道我做错了什么。同样的点通过 Postman 应用程序传递到201代码。
谢谢你的忠告!
我的代码:

function PostImportProduct()
{
var address = "https://logdemota-dev.st.test.cz:10351/MYSTOCKLOGISTICSTAWMSINT_DEV/V1/product";
var username = "API_TEST";
var password = "xxxxxx";

// Define the request body JSON string
var requestBody = '{"extIsId":"abc/777","productCode":"ExterniKodSort","name":"TA_API777","type":0,"measurementUnitCode":"KS","weightGross":1.1,"weightNett":1.1,"grossDimension":{"height":1.1,"width":1.1,"depth":1.1,"volume":1.1},"pictureUrl":"www.aaa.cz/SORT.png","expirationMandatory":1,"serialNumbersRecords":{"inboundMandatory":1,"outboundMandatory":1},"batches":1,"barcodes":[{"barcode":123456,"active":1,"default":1,"measurementUnitCode":"ks"}]}surementUnitCode":"KS","warehouseCode":"3S20","weightGross":10.5,"weightNett":9.5,"grossDimension":{"height":2,"width":1.5,"depth":3.5,"volume":10.5},"pictureUrl":"","expirationMandatory":1,"serialNumbersRecords":{"inboundMandatory":1,"outboundMandatory":1},"batches":1,"barcodes":[{"barcode":"EAN80","active":1,"default":1,"measurementUnitCode":"KS"},{"barcode":"EAN81","active":1,"default":0,"measurementUnitCode":"KS"}]}';

// Convert the user credentials to base64 for preemptive authentication
var credentials = aqConvert.VarToStr(dotNET.System.Convert.ToBase64String
(dotNET.System_Text.Encoding.UTF8.GetBytes_2(username + ":" + password)));

Log.Message(credentials)

var aqHttpRequest = aqHttp.CreatePostRequest(address, username, password);
// Send the Authorization header with a request
aqHttpRequest.SetHeader("Authorization", "Basic " + credentials);

var aqHttpResponse = aqHttpRequest.Send(requestBody);

// Read the response data
Log.Message(aqHttpResponse.AllHeaders); // All headers

Log.Message(aqHttpResponse.StatusCode); // A status code
Log.Message(aqHttpResponse.StatusText); // A status text
Log.Message(aqHttpResponse.Text); // A response body
}```
cedebl8k

cedebl8k1#

你试过json.stringify()吗?

var requestBody = JSON.stringify({
                    extIsId: "abc/777",
                    productCode: "ExterniKodSort",
                    name: "TA_API777"
                    .... // add all params you need
                })
var aqHttpResponse = aqHttpRequest.Send(requestBody);

相关问题