2015-04-17 93 views
0

我正在使用Appcelerator爲iOS和Android構建應用程序。與Appcelerator一起使用POST時出現Android HTTP錯誤

部分應用程序需要HTTP POSTs到API。

這適用於iOS很大,但未能在Android上,讓我在這個過程中這個錯誤...

[ERROR] : TiHttpClient: org.apache.http.client.HttpResponseException: Not Acceptable 

我知道有可能是Android中如何處理這些電話有一些差別,但我米並不完全確定我需要改變他們的工作。

這是我正在打的電話之一。

任何關於我可能做錯的指針?

function doRegister() { 
      // check to see if we already have a username saved 
      if (!Ti.App.Properties.getString('userEmail')) { 

       var userEmailfromBox = Ti.App.Properties.getString('userEmailfromBox'); 
       var HashedEmail = Ti.Utils.sha256(userEmailfromBox); 

       var registerData = { 
        "account": { 
         "name": userEmailfromBox, 
         "mail": userEmailfromBox, 
         "pass": HashedEmail, 
         "field_user_type": { 
          "und": "xxxxx" 
         } 
        } 
       }; 

       var registration = Ti.Network.createHTTPClient({ 
        onload: function() { 
         // handle the response 
         Ti.API.info(this.responseText); 

         // need to save this email so we don't keep registering the user 
         Ti.App.Properties.setString('userEmail', userEmailfromBox); 

         // then we need to load the next step 
         doLogin(); 
        }, 
        onerror : function(e) { 
         Ti.API.info('Registering: ' + e.error); 
         //alert('error'); 

         // then we need to load the next step 
         //doLogin(); 
        } 
       }); 
       registration.open('POST', 'https://www.myurlredacted.com'); 

       // change the loading message 
       //loaderWheel.message = 'Creating User'; 
       loaderWheel.message = 'Uploading Your Photos'; 
       // show the indicator 
       loaderWheel.show(); 

       // set the header for the correct JSON format 
       registration.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 
       // send the data to the server 
       registration.send(JSON.stringify(registerData)); 

      } else { 
       // user is already registered, so skip them onto the next step 
       Ti.API.info('user already registered'); 
       // then we need to load the next step 
       doLogin(); 
      } 

     } 

回答

0

我只是跑基於你的下面的代碼:

var url = "http://requestb.in/1iuahxb1"; 

var registerData = { 
    "account": { 
     "name": 'userEmailfromBox', 
     "mail": 'userEmailfromBox', 
     "pass": 'HashedEmail', 
     "field_user_type": { 
      "und": "xxxxx" 
     } 
    } 
}; 

var registration = Ti.Network.createHTTPClient({ 
    onload: function() { 
     // handle the response 
     Ti.API.info(this.responseText); 
    }, 
    onerror: function (e) { 
     Ti.API.info('Registering: ' + e.error); 
    } 
}); 

registration.open('POST', url); 

// set the header for the correct JSON format 
registration.setRequestHeader("Content-Type", "application/json; charset=utf-8"); 
// send the data to the server 
registration.send(JSON.stringify(registerData)); 

它運行沒有錯誤和requestb.in臨危帖子:

http://requestb.in/1iuahxb1?inspect

+0

你認爲它可能是服務器端的東西,那是造成的錯誤?它正在創建一個在Drupal中創建的API。 –

+0

我想。由於錯誤說響應中有一個異常,它看起來像Drupal正在返回它無法處理的東西。你將不得不攔截Drupal發送的調試信息。 –

相關問題