JSON请求对象钛不发布

时间:2014-07-04 22:26:21

标签: json titanium titanium-mobile

这是我的帖子请求:

exports.APIPostRequest = function(url, JSONObj, callback, errorCallback) {
    Ti.API.info('Get Request is called');
    var req = Titanium.Network.createHTTPClient({
        onload : callback,
        onerror : errorCallback,
        timeout : 60000
    });
    req.open("POST", url);
    req.setRequestHeader('Content-Type', 'application/json');

    //JSON object goes into send method.
    req.send(JSONObj);
};

在我提出要求后。

发出帖子请求后,它不会发送JSON对象。

{“facebook_token”:“dasdaddasd”,“date_of_birth”:“503435231.0”,“gender”:“male”,“ethnicity”:“”,“description”:“ls lsls”,“nickname”:“ffsfs “}

现在当我发布它时,api抱怨它的格式不正确:

{
    "facdebook_scriptioken":"BAACMVus3xYsdwqdAdkSGzrr0vFscmDK=IuA%20zW4QYlovSziJJCmrpFtyNl8edfR4hVU1ZAv60yHqFP7yEJ8g6SSrmvibt9Grw7L%27xIsALM0mVWsZBTRcYAIPzy%23npG6SKE12sAcno0kWVhg5LZAljqM0ZBzUtsZA8W9zife%21&publiGdWLc_name=0wbjEx4xGU&genwAJiZAder=malwFF9ZBmUe&ev8gGjDgZDZD",
    "thnickname":"jsm",
    "ity=&date_of_birth": =503435231,
    "gender":"male",
    "public_name": false,
    ".0&body_type":"thin",
    "devi=&facebook_token": "ad=CAAUYyAuheuQrc0BAKRqYidhw2gFK1GSmniDZddadwoKblpLIVZC1fwTpfhwugRIabmiZBZANfh0ZAV67I9QowuehfiwhfweqonD5IaRZApgWkgfhpODKJ2KGLIdwWt89KyCZBy9UMPmjIbZBGxN64IZCkZAFLMk6KapBHqU4no98MoSZBtqRHguYJnImQ8tV1bEFfSZBqzShaeiw"
    "sD9kAfTN2F3xethZAXqTfEob2vqUVk5pXsAqsYZD&nicity":"",
    "dknamesc=Pription":"thices is m%dadad"
}

完全慌乱,为什么会这样,欢呼?

  {
        "facebook_t": "Bdadadadsadadadad",
        "niame": "jsm",
        "publethnic_name": false,
        "body_itype": "thAsan",
        "devscrice_ptioken": "aduhI loveu my lidhwihwufefwpfhwu!",
        "nifhwucknamehf": "Priwhfwncefhwhifwufhss eiw",
        "ethnpublicity_name": "0",
        "bodescripy_tionype": "Prefer not thiso dis mclose."
    }

2 个答案:

答案 0 :(得分:0)

执行JSON.Stringify并让我知道是否仍然抱怨相同的

xhr.send(JSON.stringify(JSONObj))

由于

答案 1 :(得分:0)

要发送POST请求(表单数据),您必须将content-type标头设置为

req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");