Jump to content
СофтФорум - всё о компьютерах и не только

Что не так в моей функции?


Recommended Posts

Я на 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...