NetSuite Rest Web服务C#RestSharp-请求失败,而状态代码BADREQUEST
在这个电话中,我继续将头撞在墙上。它在Postman中返回完全很好,但是当我跑步时,我会得到以下内容:
例外消息:发生一个或多个错误。 (请求因状态代码badrequest失败)。
例外数据:system.collections.listDictionaryInternal
我正在尝试使用最新的RestSharp构建,但可能必须降级才能使其正常工作,以便我可以使用提供的Postman代码。我还确保在运行脚本之前要获得有效的令牌。
*请注意,该代码在VS中构建正常。
using System;
using RestSharp;
using System.Net.Http;
using System.Threading.Tasks;
namespace NetSuite
{
class Program
{
static void Main(string[] args)
{
try
{
MainAsync().Wait();
static async Task MainAsync()
{
var client = new RestClient("https://xxxxxxxxxxxxxxxxxxx.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=500");
var request = new RestRequest();
request.AddHeader("Content-Type", "application/json");
request.AddHeader("prefer", "transient");
request.AddHeader("Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
var body = @"{""q"": ""SELECT * FROM entity where id = 999""}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
var response = await client.PostAsync(request);
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR -- Exception Message: " + ex.Message.ToString());
Console.WriteLine("ERROR -- Exception Data: " + ex.Data.ToString());
System.Threading.Thread.Sleep(300);
}
}
}
}
I continue to bang my head against the wall on this call. It returns perfectly fine in postman, but when I run through VS I get the following:
Exception Message: One or more errors occurred. (Request failed with status code BadRequest).
Exception Data: System.Collections.ListDictionaryInternal
I am trying to use the latest RestSharp build, but might have to downgrade to get it working so I can just use the Postman code provided. I've ensured to get a valid token before running the script as well.
*Note that the code builds fine in VS.
using System;
using RestSharp;
using System.Net.Http;
using System.Threading.Tasks;
namespace NetSuite
{
class Program
{
static void Main(string[] args)
{
try
{
MainAsync().Wait();
static async Task MainAsync()
{
var client = new RestClient("https://xxxxxxxxxxxxxxxxxxx.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=500");
var request = new RestRequest();
request.AddHeader("Content-Type", "application/json");
request.AddHeader("prefer", "transient");
request.AddHeader("Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
var body = @"{""q"": ""SELECT * FROM entity where id = 999""}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
var response = await client.PostAsync(request);
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR -- Exception Message: " + ex.Message.ToString());
Console.WriteLine("ERROR -- Exception Data: " + ex.Data.ToString());
System.Threading.Thread.Sleep(300);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少身份验证代码。这是使用您的SUITEQL请求的示例。我发现RestSharp无法与方法相关。浪费了一天,然后决定尝试一种方法。它可以正常工作。 Get the token information found in the tutorial at
You're missing the authentication code. Here is a sample using your suiteql request. I have found that RestSharp will not work with the Method.Option for the test post in the NetSuite Rest API Tutorial Postman sample. Wasted a day on that and then decided to try a Method.Post it it worked fine. Get the token information found in the tutorial at NetSuite Getting Started with Token-based Authentication