2011-01-10 10 views
8

実際には私はAndroidで新しく、今では自分のプロジェクトにクッキーを追加する必要があります。私はHttpsUrlConnectionを使用しています。ここではどのように私はリクエストを作成しているとWebサーバーからの応答を取得し、今私はクッキーを追加する必要があります。アンドロイドのHttpsURLConnectionでクッキーを使用する方法

URL url = new URL(strUrl); 

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); 

connection.setRequestMethod("POST");  

connection.setRequestProperty("Content-Type", 
    "application/soap+xml; charset=utf-8"); 

    connection.setRequestProperty("Content-Length", ""+ 
      Integer.toString(request.getBytes().length)); 

    connection.setUseCaches (false); 
    connection.setDoInput(true); 
    connection.setDoOutput(true); 


    // send Request... 
    DataOutputStream wr = new DataOutputStream (connection.getOutputStream()); 
wr.writeBytes (request); 
wr.flush(); 
wr.close(); 

//Get response... 
DataInputStream is = new DataInputStream(connection.getInputStream());  
String line; 
StringBuffer response = new StringBuffer(); 
while((line = is.readLine()) != null) { 
    response.append(line); 
    } 
is.close(); 
FileLogger.writeFile("Soap.txt", "RESPONSE: " + methodName + "\n" + response); 
HashMap<String, String> parameters = null; 
try { 
    parameters = SoapRequest.responseParser(response.toString(), methodName); 
    } catch (ParserConfigurationException e) { 
    // TODO Auto-generated catch block 
e.printStackTrace(); 
} catch (SAXException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
return parameters; 

任意のヘルプは感謝になります、ありがとう

答えて

14

あなたはチュートリアルhereを持っている(URLConnectionのためですが、それも動作するはずですので、HttpsURLConnectionはサブクラスです)。

基本的にあなたがしなければならない。

1つまたは "userId=igbrown; sessionId=SID77689211949; isAuthenticated=true"多くの場合場合 myCookieフォーム "userId=igbrown"を持って
connection.setRequestProperty("Cookie", myCookie); 

(セパレータはセミコロンと空白である)

関連する問題