小编mic*_*l92的帖子

负数组大小异常

我是 Blackberry 的新手,我正在尝试以 xml 格式将搜索词发布到服务器。但我不断收到此错误Request Failed. Reason Java.lang.NegativeArraySizeException

我想在解析数据之前检查连接是否有效,所以从这个连接中,我希望收到 xml 中的响应文本。下面是代码:

public void webPost(String word) {
    word = encode (word);
    String responseText;
    try{
        HttpConnection connection = (HttpConnection)Connector.open("http://some url.xml");
        connection.setRequestMethod(HttpConnection.POST);
        connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
        String postData = "username=loginapi&password=myapilogin&term="+ word;
        connection.setRequestProperty("Content-Length",Integer.toString(postData.length()));
        connection.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.0");
        OutputStream requestOut = connection.openOutputStream();
        requestOut.write(postData.getBytes());

        InputStream detailIn = connection.openInputStream();
        byte info[]=new byte[(int)connection.getLength()];
        detailIn.read(info);
        detailIn.close();
        requestOut.close();
        connection.close();
        responseText=new String(info);
        requestSuceeded(requestOut.toString(), responseText);
    }
    catch(Exception ex){
        requestFailed(ex.toString());
    }
}

private void requestSuceeded(String result, String responseText) {
    if(responseText.startsWith("text/xml")) { 
        String strResult = new String(result); …
Run Code Online (Sandbox Code Playgroud)

post blackberry http java-me

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

blackberry ×1

http ×1

java-me ×1

post ×1