通过POST的Sugar CRM REST API调用始终返回文档

时间:2014-06-20 17:54:07

标签: rest sugarcrm

我正在向Sugar 6.5.4服务器发出以下登录API请求(使用Fiddler),所有我收到POST请求的都是SugarWebServiceImplv4_1.php的文档。我希望得到一个带有会话ID的JSON响应(或错误?)。

我做错了什么?

我已尝试过v2,v2.1,v3,v3.1,v4和v4.1服务网址;所有人都将其各自的文件作为回复发布。

请求

POST https://sugarserver/service/v4_1/rest.php HTTP/1.1
Accept: application/json
Host: sugarserver
Content-Length: 180
Expect: 100-continue
Connection: Keep-Alive

method=login&input_type=JSON&response_type=JSON&rest_data={"user_auth":{"user_name":"username","password":"md5passwd"},"application_name":"test"}

响应

HTTP/1.1 200 OK
Date: Fri, 20 Jun 2014 17:39:16 GMT
Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.5
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
Content-Length: 39895

<pre>/**
 * SugarWebServiceImplv4_1.php
 *
 * This class is an implementation class for all the web services.  Version 4_1 adds limit/off support to the
 * get_relationships function.  We also added the sync_get_modified_relationships function call from version
 * one to facilitate querying for related meetings/calls contacts/users records.
 *
 */
Class [ <user> class SugarWebServiceImplv4_1 extends SugarWebServiceImplv4 ] {

...

另一方面,如果我发送GET请求,那么我会得到有效的回复。为什么POST不起作用?

使用POST,我无法将rest_data参数 - 或没有rest_data参数名称的原始JSON对象 - 移动到请求正文中,都会导致“无效登录”JSON响应。

请求

GET https://sugarserver/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON&rest_data=%7B%22user_auth%22:%7B%22user_name%22:%22username%22,%22password%22:%22md5passwd%22%7D,%22application_name%22:%22test%22%7D HTTP/1.1
Accept: application/json
Host: sugarserver
Connection: Keep-Alive

响应

Date: Fri, 20 Jun 2014 20:56:05 GMT
Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.5
Set-Cookie: PHPSESSID=redacted; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 967
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

{"id":"redacted","module_name":"Users","name_value_list"...}

2 个答案:

答案 0 :(得分:3)

呃 - 这是请求中的内容类型。必须为URL编码的表单设置,然后POST请求才能正常工作。

Content-Type: application/x-www-form-urlencoded; charset=UTF-8

答案 1 :(得分:2)

尝试通过http而不是https点击您的服务器,看看它做了什么......否则,使用您的浏览器点击端点https://sugarserver/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON只是为了看看您是否收到JSON或者当我尝试时...在我的生产服务器上,我收到一条JSON编码的错误消息:

{"name":"Invalid Login","number":10,"description":"Login attempt failed please check the username and password"}