Google에서 Https Post Request를 보내고 로그인 한 후 다음 페이지의 소스 코드를 가져 와서 "Android에서" 동영상을 많이 보지만 아무것도 작업이 코드에서 모든 제발 도와주세요 :Https Post 요청이 Android에서 작동하지 않습니다.
public class MainActivity extends Activity {
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.textView2);
try {
new DownloadSourceCodeTask().execute("Link");
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Error in Main", Toast.LENGTH_LONG)
.show();
}
} private InputStream OpenHttpConnection(String urls) throws IOException {
InputStream in = null;
int response = -1;
URL url = new URL(urls);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not An Http Connction");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
String param="ssousername=" + URLEncoder.encode("usernamevalue","UTF-8")+
"password="+URLEncoder.encode("passwordvalue","UTF-8");
httpConn.setDoOutput(true);
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("POST");
httpConn.setFixedLengthStreamingMode(param.getBytes().length);
httpConn.setRequestProperty("Content-Type", "text/html; charset=WINDOWS-1256");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception e) {
Log.d("Networking", e.getLocalizedMessage());
}
return in;
}
private String DownloadSourceCode(String url){
int BUFFER_SIZE = 2000;
InputStream in = null;
try {
in=OpenHttpConnection(url);
} catch (IOException e) {
Log.d("Error in connection",e.getLocalizedMessage());
return "";
}
InputStreamReader isr = new InputStreamReader(in);
int charRead;
String str = "";
char[]inputBuffer = new char[BUFFER_SIZE];
try{
while((charRead = isr.read(inputBuffer))>0){
String readString = String.copyValueOf(inputBuffer,0,charRead);
str+=readString;
inputBuffer = new char[BUFFER_SIZE];
}
in.close();
}catch(IOException e){
Log.d("Error in connection",e.getLocalizedMessage());
return "";
}
return str;
}
private class DownloadSourceCodeTask extends AsyncTask<String , Void , String>{
ProgressDialog dialog;
protected String doInBackground(String... urls){
return DownloadSourceCode(urls[0]);
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(MainActivity.this, "",
"Loading. Please wait...", true);
}
protected void onPostExecute(String result){
if(dialog.isShowing()){
dialog.cancel();
}
text.setText(result);
}
}
}
스택 오버플로는 Q & A 리소스이며 디버깅 서비스가 아닙니다. "이 코드로 도와주세요"는 질문이 아닙니다. 문제가 무엇인지 설명하십시오. 어느면에서 작동하지 않습니까? 어떤 결과를 얻고 있으며 원하는 결과와 어떻게 다른가요? 수신 한 모든 오류 메시지를 축 어적으로 포함하십시오 (단지 설명 만하지 마십시오). –
나는 https 웹 사이트에서 로그인 페이지에 사용자 이름과 암호를 게시해야합니다. 좋아요. 인터넷에서 많이 찾았지만 icannt가이 코드를 찾았지만 작동하지 않습니다. 여전히 오류 메시지가 나타납니다. 많은 일을 그때 curshing, 어떤 도움을 실행하시기 바랍니다 – SaeedDroid