Why can't I delete a file from parse.com? Here is my method.
URL url = new URL("https://api.parse.com/1/files/"+ parseFileName);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty ("X-Parse-Master-Key", Sett.PARSE_MASTER_KEY);
conn.setRequestProperty ("X-Parse-Application-Id", Sett.PARSE_APP_ID);
conn.setRequestProperty ("X-Parse-REST-API-Key", Sett.PARSE_REST_KEY);
conn.setRequestProperty ("Content-Type", "application/json");
conn.setRequestMethod("DELETE");
String responseStr = conn.getResponseMessage();
String responseCode = String.valueOf(conn.getResponseCode());
Result = 200 OK, but the file is still available for download. Also, I tried to send a request through the control panel from Parse.com. Result was null
This is a link to file I triying to delete http://files.parsetfss.com/5592cbfd-6fd4-41ca-8a82-dd90ebcd6541/tfss-410de5c1-bbac-4772-8be5-45b4f55d47fd-1450985755273
Related
I used to get the following response to php request
Response:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
my code:
URL url = new URL("http://myappdemo.com/payumoney/payUmoneyHashGenerator.php");
// get the payuConfig first
String postParam = postParams[0];
byte[] postParamsByte = postParam.getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setInstanceFollowRedirects(false);
conn.setRequestProperty("Content-Length",
String.valueOf(postParamsByte.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postParamsByte);
InputStream responseInputStream = conn.getInputStream();
StringBuffer responseStringBuffer = new StringBuffer();
byte[] byteContainer = new byte[1024];
for (int i; (i = responseInputStream.read(byteContainer)) != -1; ) {
responseStringBuffer.append(new String(byteContainer, 0, i));
}
Log.e("tag", "doInBackground: "+ responseStringBuffer.toString());
also tried with volley reponse was
BasicNetwork.performRequest: Unexpected response code 301 for
http://myappdemo.com/payumoney/payUmoneyHashGenerator.php
.
Please help me.
Thanks in Advance.
301 Moved Permanently is used for permanent URL redirection.Current links using the URL that the response is received for should be updated. try to use https:// in your link
use URL url = new URL("https://myappdemo.com/payumoney/payUmoneyHashGenerator.php");
I have prepared one API, and I want to send one specific data with json posting.
My code works fine during working with Fiddler or site side.
But the problem is why some character didn't send, when we use Android version as a client device.
For example:
string a="mn✈" // correct on any device (android,site,Fiddler,...)
string b="mn✉" //correct on any device except(android) //getting 500 reponse
String requestURL = Utils.SERVER_URL + "PostJsonFeatures";
HttpURLConnection conn = (HttpURLConnection) new URL(requestURL).openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");
JSONObject postDataParams = new JSONObject();
postDataParams.put("Features", getAttributes());
postDataParams.put("productId", productId);
postDataParams.put("groupId", catId);
postDataParams.put("brandId", PrefManager.getInstance(context).getCompanyId());
postDataParams.put("languageId", PrefManager.getInstance(context).getLanguageApi());
DataOutputStream printout = new DataOutputStream(conn.getOutputStream ());
printout.write(postDataParams.toString().getBytes());
printout.flush ();
printout.close ();
You can decode to string and pass in url.
String parseString = URLDecoder.decode(URLEncoder.encode(myString, "UTF-8"), "ISO-8859-1");
I'm trying to have my android app execute code where it opens a URL connection to a local php file that returns database entries in JSON format, but it's not connecting, after commenting out the other lines I can see that it throws an exception at the lines:
connection = (HttpURLConnection) url.openConnection();
connection.connect();
Heres the screen shot of android code and the error log, the returned expected json file in windows and the php file:
link
Can you change your
URL url = new URL(getListUrl);
into
URL url = new URL("http://www.google.com");
and check the incoming data.
and the following is a working example.
try {
URL url = new URL("http://www.google.com");
URLConnection urlConn = url.openConnection();
if (!(urlConn instanceof HttpURLConnection)) {
throw new IOException("URL Exception");
}
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
resCode = httpConn.getResponseCode();
if (resCode == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
}
catch (MalformedURLException e) {
e.printStackTrace();
}
My argument is if this code works for remote urls, it should work with localhost as well.
Hi it must be that you are using wrong local ip address in android files
it should be 10.0.2.2 not 127.0.0.1
First tell me are you testing on emulator or device
if emulator then where you define file path it should be
http://10.0.2.2/request_entries.php
just like in code
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://10.0.2.2/request_entries.php");
Managed to get the input stream using the URL:
URL url = new URL("http://10.0.2.2/request_entries.php");
result
Thanks a bunch guys :)
please help me out with this problem.
I want to make a POST call with JSON data that should appear in body to request but i am not able to do that. I made POST call and getting data but data is not in JSON format.
Code :
data = "{'mobile':'"+mobile_number+"','password':'"+mypassword+"'}";
byte[] dataPost = data.getBytes();
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
urlConnection.setInstanceFollowRedirects(false);
urlConnection.setRequestProperty("Accept", "application/json");
//urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("charset", "UTF8");
urlConnection.setUseCaches(false);
OutputStream os = urlConnection.getOutputStream();
os.write(dataPost);
os.close();
Result is coming like below
body:
{'a':'b','c':'d'}:""
Please Help me. i am new to android Development.
Thanks
I am trying to insert data to a mysql table using the below methods but am not able to do so. Any idea on where I may be going wrong?
Method 1: Using HTTPClient to directly access the URL. Below is the code:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("http://<lclhst>/GnPServlet/GetNpostServlet/? account=1&password=123");
HttpResponse execute = client.execute(httpPost);
Method 2: Using URL connection to directly access the URL. Below is the code:
URL url = new URL("http://<lclhst>/GnPServlet/GetNpostServlet/? account=1&password=123");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Accept", "application/octet-stream");
conn.connect();
Method 3: Using Arraylist to pass values.
When i run the URL from the browser i get the success message "Inserted" and the data is inserted into the DB. But the same when tried through the app does not insert data. Below is the servlet code:
private String accountLookup(String acct, String pwd)
{
Connection con = null;
Statement st = null;
StringBuffer msgb = new StringBuffer("");
try
{
// These will vary depending on your server/database
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbone?user=root&password=root");
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into accttbl(address, description, time) values ('test 07-jul',ok,12:12)");
return "Inserted";
}
catch (Exception e)
{
return e.toString();
}
}
The below code inserts data but it opens the browser which I dont want. Also the data insertion is not always successful.
String url = "http://10.0.2.2:8080/GnPServlet/GetNpostServlet";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
conn.setRequestMethod("POST");
Looks like you're sending a POST when the servlet expects a GET (which is what the browser would send if you just paste the URL into the URL bar)
conn.setRequestMethod("GET");
...is most likely what you want since your parameters are encoded in the URL.
Also, are you sure that the spaces in your URL before account should be there?