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

标签 rest sugarcrm

我正在向 Sugar 6.5.4 服务器发出以下登录 API 请求(使用 Fiddler),而我通过 POST 请求返回的只是 SugarWebServiceImplv4_1.php 的文档。我希望获得带有 session ID 的 JSON 响应(或错误?)。

我做错了什么?

我已尝试过 v2、v2.1、v3、v3.1、v4 和 v4.1 服务 URL;所有人都发布了各自的文档作为回应。

请求

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"...}

最佳答案

呃 - 这是请求的内容类型。必须将其设置为 URL 编码表单,然后 POST 请求才有效。

内容类型:application/x-www-form-urlencoded;字符集=UTF-8

关于rest - Sugar CRM REST API 通过 POST 调用始终返回文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333036/

相关文章:

通过 REST : Share a jar with class definitions? 进行 Java 到 Java 的对话

javascript - SugarCRM 企业 6.5 - "app is not defined"

sugarcrm - 升级SugarCRM

rest - 如何为单个资源建模RESTful API?

rest - REST API 包装器是否应该在发出请求之前验证输入?

javascript - SugarCRM 旧版 (v6) 中的自定义验证

php - 在 SugarCRM 中将国家/地区文本字段更改为下拉列表

exception - 在Zend Application中的error.log文件中捕获错误和异常的最佳方法是什么?

rest - REST API 如何有效地处理分页?

java - 如何在REST应用程序中获取 "X-Forwarded-Proto" header ?