android HTTP post请求返回错误

时间:2017-04-28 12:18:45

标签: javascript android http-post

我正在尝试点击网址。服务器端是一个java脚本,如下所示

function interact(message){
// loading message
$('<div class="message loading new"><figure class="avatar"><img 
src="/static/res/im.png" /></figure><span></span>
</div>').appendTo($('.mCSB_container'));
// make a POST request [ajax ]
$.post('/message', {
    msg: message,
}).done(function(reply) {


$('.message.loading').remove();

$('<div class="message new"><figure class="avatar"><img src="/static/res/botim.png" /></figure>' + reply['text'] + '</div>').appendTo($('.mCSB_container')).addClass('new');
setDate();
updateScrollbar();

我通过http android客户端

调用它
    public void postData(String valueIWantToSend) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://10.28.2.1:5000/message");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("message", valueIWantToSend));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

网址已被点击但其显示错误请求

"POST /message HTTP/1.1" 400 -

1 个答案:

答案 0 :(得分:0)

10.28.2.1:5000是您的本地服务器吗?如果是 - 请下载并安装ngrok并在控制台ngrok http 5000中运行。你有一个链接,而不是从任何带有来自控制台的url的设备连接到本地服务器(就像miekka12kupa.ngrok.io一样(它将在控制台中编写)。使用此URL从android设备连接