Colix Posted March 18, 2008 Report Share Posted March 18, 2008 Я на Java новичок и вот пытаюсь передать POST запрос, на который сервер возращает ошибку, код которой я даже не могу прочитать, так как он в непонятной кодировке... Вот мой код: Code: private void httpConn(){ HttpConnection conn = null; OutputStream os = null; InputStream is = null; DataInput di = null; int year, month, day, classNumber; String url = ""; classNumber = (Integer.parseInt(tfClass.getString())) + 1426; if(cgAB.isSelected(1)){ classNumber++; } year = Integer.parseInt(tfYear.getString()); month = Integer.parseInt(tfMonth.getString()); day = Integer.parseInt(tfDay.getString()); url = "mypage/script.php"; try{ System.out.println("url:" + url); conn = (HttpConnection)Connector.open(url); conn.setRequestMethod(HttpConnection.POST); //String postData = "rqstdClsCode=" + classNumber + "&rqstdYear=" + year + "&rqstdMonth=" + month + "&rqstdDay=" + day + "&idF=2"; String postData = "rqstdClsCode=1436&rqstdYear=2008&rqstdMonth=3&rqstdDay=9&idF=2"; conn.setRequestProperty("Content-Type", "text/plain"); System.out.println("open os"); os = conn.openOutputStream(); os.write(postData.getBytes()); System.out.println("open is"); is = conn.openInputStream(); char buff = 4096; int len; byte []data = new byte[buff]; do{ System.out.println("READ"); len = is.read(data); if(len > 0){ System.out.println(new String(data, 0, len)); stringItem1.setText(new String(data, 0, len)); } }while(len>0); System.out.println("DONE"); }catch(Exception e){ e.printStackTrace(); }finally{ System.out.println("Close connection"); try{ os.close(); }catch(Exception e){} try{ is.close(); }catch(Exception e){} try{ conn.close(); }catch(Exception e){} } } Поправьте, что не так? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now