javascript - weex POST請求web端body服務器獲取不到參數
問題描述
POST請求服務器取不到參數,發現Stream.fetch采用的是直接將body變成字符串專遞給服務器,而我們的服務器需要的像Jquery那個樣的Ajax請求(&key=value)的形式,在charles攔截的到參數在request中為key值,而jquery中得到的是keyValue樣式,請問在哪個文件里面修改提交body的方式?
stream.fetch({
method: ’POST’, url: POST_URL, type:’json’,
//headers: {’Content-Type’: ’application/json; charset=utf-8’,},
body: JSON.stringify({ data: bodyString})//or you can just use JSON Object {username:’weex’} }, function(ret) { if(!ret.ok){ me.postResult = 'request failed'; }else{ console.log(’get:’+JSON.stringify(ret)); me.postResult = JSON.stringify(ret.data); } },function(response){ console.log(’get in progress:’+response.length); me.postResult = 'bytes received:'+response.length; });
問題解答
回答1:在請求頭中加入 'Content-Type': ’application/x-www-form-urlencoded;即可
回答2:stream.fetch({
method: ’POST’, url: POST_URL, type:’json’, body:JSON.stringify({username:’weex’})//or you can just use JSON Object {username:’weex’} }, function(ret) { if(!ret.ok){ me.postResult = 'request failed'; }else{ console.log(’get:’+JSON.stringify(ret)); me.postResult = JSON.stringify(ret.data); } },function(response){ console.log(’get in progress:’+response.length); me.postResult = 'bytes received:'+response.length; });
相關文章:
1. python - 使用xlsxwriter寫入Excel, 只能寫入65536 無法繼續寫入.2. Python做掃描,發包速度實在是太慢了,有優化的方案嗎?3. objective-c - ios百度地圖定位問題4. java - Web開發 - POI導出帶有下拉框的Excel和解決下拉中數組過多而產生的異常5. java - 微信退款,公賬號向個人轉賬SSL驗證失敗6. java - 安卓接入微信登錄,onCreate不會執行7. python - flask如何創建中文列名的數據表8. javascript - 關于定時器 與 防止連續點擊 問題9. 微信開放平臺 - Android調用微信分享不顯示10. python - mysql 如何設置通用型字段? 比如像mongodb那樣
