【问题标题】:android HTTP post request returns bad errorandroid HTTP post请求返回错误错误
【发布时间】:2017-04-28 12:18:44
【问题描述】:

我正在尝试访问 URL。服务器端是一个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);

URL 被命中但显示错误请求

"POST /message HTTP/1.1" 400 -

【问题讨论】:

  • 消息是文件还是什么...?
  • 不是文件...实际上,该 js 代码用于具有聊天界面的网站.. 当我在浏览器中点击 url 'http //10.28.2.1:5000' 时,它会给出一个文本框.. . 输入消息并发送的位置。

标签: javascript android http-post


【解决方案1】:

10.28.2.1:5000 是您的本地服务器吗?如果是 - 下载并安装 ngrok 并在控制台中运行 ngrok http 5000 。你得到了一个链接,然后你从任何设备连接到本地服务器,使用控制台的 url(就像 miekka12kupa.ngrok.io (它将写在控制台中)。使用这个 URL 从 android 设备连接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多