Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- HttpPost request = new HttpPost(SERVICE_URI + "/LoginUser");
- request.setHeader("charset", "utf-8");
- request.setHeader("Content-Type", "application/json");
- HttpParams params = request.getParams();
- HttpConnectionParams.setConnectionTimeout(params, 3000);
- HttpConnectionParams.setSoTimeout(params, 3000);
- // Build JSON string
- JSONStringer loginData = new JSONStringer()
- .object()
- .key("userName").value("TEST001")
- .key("SecurityKeyCode").value("PKEY0001")
- .endObject();
- StringEntity entity = new StringEntity(loginData.toString());
- Toast toastB = Toast.makeText(getApplicationContext(),
- loginData.toString() + "\n",
- Toast.LENGTH_SHORT);
- toastB.show();
- request.setEntity(entity);
- // Send request to WCF service
- DefaultHttpClient httpClient = new DefaultHttpClient();
- HttpResponse response = httpClient.execute(request);
- InputStream inputStream = response.getEntity().getContent();
- InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- StringBuilder stringBuilder = new StringBuilder();
- String bufferedStrChunk = null;
- while((bufferedStrChunk = bufferedReader.readLine()) != null){
- stringBuilder.append(bufferedStrChunk);
- }
- Toast toastX = Toast.makeText(getApplicationContext(),
- bufferedStrChunk + "\n",
- Toast.LENGTH_SHORT);
- toastX.show();
- Toast toastA = Toast.makeText(getApplicationContext(),
- response.getStatusLine().getStatusCode() + "\n" + request.toString() + "\n",
- Toast.LENGTH_SHORT);
- toastA.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement