Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate_subuser.java
More file actions
Latest commit
54 lines (42 loc) · 1.85 KB
/
Copy pathupdate_subuser.java
File metadata and controls
54 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.io.OutputStream;
importjava.io.OutputStreamWriter;
importjava.net.HttpURLConnection;
importjava.net.URL;
importjava.net.URLConnection;
importjava.util.stream.Collectors;
publicclassupdate_subuser {
publicstaticvoidmain(String[] args) throwsIOException {
// Details retrieved from the Authentication part.
StringuserId = "";
Stringtoken = "";
intsubuserId = 0; // Retrieved from "Get Subusers"
// Details of the subuser you wish to change
Stringpayload = "{\"password\":\"new_password\",\"traffic_limit\":0}";
URLurl = newURL("https://api.decodo.com/v1/users/"+userId+"/sub-users/"+subuserId);
URLConnectionconnection = url.openConnection();
HttpURLConnectionhttpConn = (HttpURLConnection) connection;
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0");
httpConn.setRequestProperty ("Authorization", "Token "+token);
httpConn.setRequestMethod("PUT");
httpConn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
httpConn.setRequestProperty("Accept", "application/json");
httpConn.setDoOutput(true);
OutputStreamoutStream = httpConn.getOutputStream();
OutputStreamWriteroutStreamWriter = newOutputStreamWriter(outStream, "UTF-8");
outStreamWriter.write(payload);
outStreamWriter.flush();
outStreamWriter.close();
outStream.close();
if (200 <= httpConn.getResponseCode() && httpConn.getResponseCode() <= 299) {
BufferedReaderbr = newBufferedReader(newInputStreamReader(httpConn.getInputStream()));
System.out.print(br.lines().collect(Collectors.joining()));
} else {
BufferedReaderbr = newBufferedReader(newInputStreamReader(httpConn.getErrorStream()));
System.out.print(br.lines().collect(Collectors.joining()));
}
httpConn.disconnect();
}
}