2015-04-17 2 views
0

Я использую Appcelerator для создания приложения для iOS и Android.Ошибки HTTP HTTP при использовании POST с Appcelerator

Часть приложения требует HTTP POST для 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 recieves пост:

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

+0

Как вы думаете, это может что-то серверная сторона, которая вызывает ошибки? Это удар по API, созданному в Drupal. –

+0

Думаю. Поскольку ошибка говорит, что в ответе есть исключение, похоже, что Drupal возвращает то, что он не может обработать. Вам придется перехватить то, что отправляет Drupal для его отладки. –

Смежные вопросы