当POST无法进行RESTlet调用时,GET正常工作

时间:2017-06-02 10:03:34

标签: c# web-services netsuite

我从发布数据的C#应用​​程序中调用了两次RESTlet NetSuite Web服务--GET和POST。

GET工作正常 - 我收到成功答案。这就是它在Fiddler上的表现:

https://some.netsuite.uri&deploy=1&my_id=123&my_a_id=Test66&param=4&amount=66 HTTP/1.1
Authorization: NLAuth nlauth_account=1234567_SB9, nlauth_email=xx@xx.com, nlauth_signature=Pass123456, nlauth_role=3
Accept: application/json
Host: rest.eu1.netsuite.com
Connection: Keep-Alive

返回

success

但我认为使用POST更为正确。但它失败了:

POST https://some.netsuite.uri&deploy=1 HTTP/1.1
Authorization: NLAuth nlauth_account=1234567_SB9, nlauth_email=xx@xx.com, nlauth_signature=Pass123456, nlauth_role=3
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Host: some.netsuite.uri
Cookie: JSESSIONID=**************************************; lastUser=1234567_SB9_1282_3; NS_ROUTING_VERSION=LAGGING; NS_VER=2017.1.0
Content-Length: 51
Expect: 100-continue
Connection: Keep-Alive

my_id=123&my_a_id=Test66&param=4&amount=66

返回HTML:

An unexpected error has occurred. Please click here to notify support and provide your contact information. 

可能出现什么问题?

UPD

我已使用JSON数据更新了POST:

POST https://some.netsuite.uri&deploy=1 HTTP/1.1
Authorization: NLAuth nlauth_account=XXXXX, nlauth_email=XXXXX, nlauth_signature=XXXXX, nlauth_role=3
Accept: application/json
Content-Type: application/json; charset=utf-8
Host: rest.eu1.netsuite.com
Cookie: JSESSIONID=**************************************; lastUser=1234567_SB9_1282_3; NS_ROUTING_VERSION=LAGGING; NS_VER=2017.1.0
Content-Length: 69
Expect: 100-continue

{"my_id":"975","my_a_id":"Test66","param":"4","amount":"66"}

得到答案:

    HTTP/1.1 200 OK
    Date: Sat, 03 Jun 2017 06:21:46 GMT
    Server: Apache
    Cache-Control: No-Cache
    Pragma: No-Cache
    Content-Length: 41
    Expires: 0
    Edge-Control: no-store
    X-N-OperationId: 486c2d20-099d-446b-9788-4816db59a1fd
    Set-Cookie: JSESSIONID=64.............................
; path=/
    NS_RTIMER_COMPOSITE: 1688996695:706172746E6572733030312E70726F642E6475622E6E65746C65646765722E636F6D:80
    P3P: CP="CAO PSAa OUR BUS PUR"
    Vary: User-Agent
    Content-Type: application/json; charset=utf-8

    org.mozilla.javascript.Undefined@54b896b0

从一方面来看,我认为HTTP/1.1 200 OK表示服务器已接受数据。但是org.mozilla.javascript.Undefined@54b896b0是什么意思?

1 个答案:

答案 0 :(得分:1)

您的请求内容类型错误Content-Type: application/x-www-form-urlencoded。 Restlet仅支持application/json。确保您在请求正文中发送有效的JSON:

{
    "my_id": 123,
    "my_a_id": "Test66",
    "param": 4,
    "amount": 66
}
相关问题