【问题标题】:How to post data to server in J2ME? Getting response from server Invalid API Key如何在 J2ME 中将数据发布到服务器?从服务器获取响应无效的 API 密钥
【发布时间】:2011-11-15 05:54:36
【问题描述】:

我正在向服务器发布一些数据,但我收到了来自服务器的{"status":false,"error":"Invalid API Key."} 响应。我的 API 密钥是正确的,但我不知道问题出在哪里。请朋友帮帮我。我尝试了很多,但我没有找到解决方案。我使用以下代码将数据发布到服务器。

public void tryingOne(String dtl){

     HttpConnection httpConn = null;
    InputStream is = null;
    OutputStream os = null;

 String url="http://api.geanly.in/ma/index?API-Key="+apikey;

    String details = "&orderInfo={\"booking\":{\"restaurantinfo\":{\"id\":\"5722\"},\"referrer\":{\"id\": \"9448476530\" }, \"bookingdetails\":{\"instructions\":\"Make the stuff spicy\",\"bookingtime\": \"2011-11-09 12:12 pm\", \"num_guests\": \"5\"}, \"customerinfo\":{\"name\":\"Vinodh SS\",   \"mobile\":\"9345245530\",  \"email\": \"vind@gmail.com\",  \"landline\":{ \"number\":\"0908998393\",\"ext\":\"456\"}}}}";
    try {

        System.out.println("url@@@@"+url);
        httpConn = (HttpConnection) Connector.open(url);
        httpConn.setRequestMethod(HttpConnection.POST);

       DataOutputStream outStream = new DataOutputStream(httpConn.openDataOutputStream());
        outStream.write(details.getBytes(),0,details.length());
        outStream.flush();
        outStream.close();

  //Reading Resp. from server
        StringBuffer sb = new StringBuffer();
        is = httpConn.openDataInputStream();
        int chr;
        while ((chr = is.read()) != -1) {
            sb.append((char) chr);
        }


        System.out.println("Response from srvr " + sb.toString());

    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        if (httpConn != null) {
            try {
                httpConn.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}

请朋友们帮帮我... 谢谢

【问题讨论】:

  • 你在服务器端调试过吗?
  • 我不知道服务器上发生了什么,因为服务器不在这里......但我会问那里发生了什么......
  • 你试过用encoded URL?发帖

标签: java-me httpconnection j2mepolish midp-2.0


【解决方案1】:

您需要修剪变量“apikey”。

我在连接 Picasa 服务器时遇到了同样的问题。

【讨论】:

【解决方案2】:

要使用HttpConnection 发送数据,请使用in this tutorial 类。它还从服务器获取响应。

【讨论】:

  • 你我用了同样的东西..但仍然得到 {"status":false,"error":"Invalid API Key."}
猜你喜欢
  • 1970-01-01
  • 2018-08-05
  • 1970-01-01
  • 2020-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多