Hey.
Ich habe ein kleines Problem. Ich probiere schon seit längerem an einer POST request rum und finde einfach das problem nicht
Mein Code:
Ausgabe:
Ich habe ein kleines Problem. Ich probiere schon seit längerem an einer POST request rum und finde einfach das problem nicht
Mein Code:
Java:
public String postReq(String URL, String[] keys, String[] values)
{
String ret = "";
//POST
try {
// Construct data
String data = URLEncoder.encode(keys[0], "UTF-8") + "=" + URLEncoder.encode(values[0], "UTF-8");
if(keys.length > 1)
{
for(int i = 1; i < keys.length; i++)
{
data += "&" + URLEncoder.encode(keys[i], "UTF-8") + "=" + URLEncoder.encode(values[i], "UTF-8");
}
}
// Send data
URL url = new URL(baseURL + URL);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
ret += line;
}
wr.close();
rd.close();
} catch (Exception e) {
System.out.print(e);
}
return ret;
}
Ausgabe:
Code:
� ݽ�rǵ��Y��;�p��h )�H/��cI��s���] Z����&{��a>��3/��d~��Vfeu7������!� [.....]