C# 为什么我的网络请求被接收为;获得;当我';m将该方法设置为";POST";?
我使用WebRequest类将数据发布到Amazon MerchantFullfillment uri(如中所述) 我明白了C# 为什么我的网络请求被接收为;获得;当我';m将该方法设置为";POST";?,c#,asp.net,.net,amazon-web-services,amazon-mws,C#,Asp.net,.net,Amazon Web Services,Amazon Mws,我使用WebRequest类将数据发布到Amazon MerchantFullfillment uri(如中所述) 我明白了 <?xml version="1.0"?> <ErrorResponse xmlns="http://mws.amazonservices.com/MerchantFulfillment/2015-06-01"> <Error> <Type>Sender</Type> <Code>
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
<Error>
<Type>Sender</Type>
<Code>InvalidParameterValue</Code>
<Message>Either Action or Operation query parameter must be present.</Message>
</Error>
<RequestID>03f0e2ca-4c30-4012-9888-c33acc83446f</RequestID>
</ErrorResponse>
我正在postData中发送操作查询参数“&Action=GetEligibleShippingServices”。这是我的代码——我更改了端点url以尝试查看请求
public void CreateAWSMessage(DateTime timestamp, ShipmentRequestDetails srd)
{
NameValueCollection awsField = new NameValueCollection();
string stringToSign = StringToSign(timestamp, srd, awsField);
string signature = CreateMessageSignature(srd, awsField, stringToSign);
string signedString = stringToSign + "&Signature=" + signature;
//string url = @"https://mws.amazonaws.com/MerchantFulfillment/2015-06-01";
string url = @"http://localhost/WebApplication1/Service.aspx";
WebRequest gess = WebRequest.Create(url);
HttpWebRequest httpGESS = (HttpWebRequest)gess;
string tmp = gess.Method;
httpGESS.Method = "POST";
httpGESS.ContentType = "x-www-form-urlencoded";
byte[] bytes = Encoding.UTF8.GetBytes(signedString);
httpGESS.ContentLength = bytes.Length;
using (Stream stream = httpGESS.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
string responseString;
using (StreamReader streamResponse = new StreamReader(httpGESS.GetResponse().GetResponseStream()))
{
responseString = streamResponse.ReadToEnd();
}
}
当我在调试WebApplication1(端点)中查看请求时,它将内容显示为空,方法显示为“GET”。这就解释了API为什么不接收操作查询参数。为什么端点看不到请求负载,或者它是一个“POST”
以下是经过消毒的signedString:
AWSAccessKeyId=myAWSAccessKeyID&Action=GetEligibleShippingServices&MWSAuthToken=myMWSAuthToken&SellerId=mySellerID&ShipmentRequestDetails.AmazonOrderId=TST-1234567-1234568&ShipmentRequestDetails.ItemList.Item.1.OrderItemId=Item1&ShipmentRequestDetails.ItemList.Item.1.Quantity=2&ShipmentRequestDetails.MustArriveByDate=2016-12-31T01%3a15%3a52Z&ShipmentRequestDetails.PackageDimensions.Height=9&ShipmentRequestDetails.PackageDimensions.Length=7&ShipmentRequestDetails.PackageDimensions.Unit=inches&ShipmentRequestDetails.PackageDimensions.Width=8&ShipmentRequestDetails.SellerOrderId=TST-1234567-1234568&ShipmentRequestDetails.ShipDate=2016-12-27T01%3a15%3a52Z&ShipmentRequestDetails.ShipFromAddress.AddressLine1=799%20Central%20Ave&ShipmentRequestDetails.ShipFromAddress.AddressLine2=&ShipmentRequestDetails.ShipFromAddress.AddressLine3=&ShipmentRequestDetails.ShipFromAddress.City=Los%20Angeles&ShipmentRequestDetails.ShipFromAddress.CountryCode=US&ShipmentRequestDetails.ShipFromAddress.Email=jp%40example.com&ShipmentRequestDetails.ShipFromAddress.Name=JP%20test&ShipmentRequestDetails.ShipFromAddress.Phone=310-555-1212&ShipmentRequestDetails.ShipFromAddress.PostalCode=90021&ShipmentRequestDetails.ShipFromAddress.StateOrProvinceCode=CA&ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp=False&ShipmentRequestDetails.ShippingServiceOptions.DeliveryExperience=DeliveryConfirmationWithoutSignature&ShipmentRequestDetails.Weight.Unit=ounces&ShipmentRequestDetails.Weight.Value=120&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-12-26T21%3a53%3a05Z&Version=2015-06-01&Signature=d9rvl0XO7CbKuR+wNvCwh56ux5oNY/wv3I6z79+fG1M
为什么不使用HttpClient?如果StringToSign方法可能已经在执行此操作,请在将字符串写入流之前尝试对其进行编码。var urlEncodedString=HttpUtility.UrlEncode(signedString);类似的内容,否则可能无法正确地包含在您的帖子中。@Woot signedString包含在内。这似乎不是MWS的问题,而是在C#中使用HttpWebRequest的问题。您可能希望查看以下内容: