我想從Java代碼呼叫到Web服務在目標C
public static void post(URL url, byte[] msg, String user, String pass) throws Exception
{
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml");
conn.setRequestProperty("Authorization", "Basic " + makeAuth(user,pass));
//conn.setRequestProperty("Content-Length", msg.length + "");
OutputStream out = conn.getOutputStream();
out.write(msg);
out.flush();
System.out.println("\n*** POST results ***");
InputStream in = conn.getInputStream();
printResults(in);
try {out.close();} catch (Exception whocares) {}
try {in.close();} catch (Exception whocares) {}
}
這裏被稱爲Web服務,其中URI是URL的Web服務進行客觀等價的C方法。 用戶和密碼是用戶名和密碼。
任何人都可以知道如何在目標c中調用相同的東西。
'post'方法屬於哪個類?什麼樣的認證(基本,摘要,NTLM等)被用來檢查用戶名和密碼? POST請求的結果會怎樣?它被丟棄了嗎?這是工作的Java代碼或你編造的東西? – Codo
對不起,這是方法調用。我已經更新了方法定義。現在你可以給我iPhone的代碼。 –