2014-07-04 129 views
0

這裏是我的POST請求:JSON請求對象鈦不會發布

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」:「男性」,「種族」:「」,「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." 
    } 

回答

0

做它JSON.Stringify,讓我知道,如果仍然抱怨同樣的

xhr.send(JSON.stringify(JSONObj)) 

感謝

+0

它仍在抱怨。 – user3754111

+0

只是雙重檢查了一個驗證器其正確的JSON,問題是所有的字段都搞砸了 – user3754111

+0

發現問題,這是服務器端的問題。這是發送JSON數據的正確方法。謝謝 – user3754111

0

要發送POST請求(表單數據),你將需要設置內容類型頭到

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