Communication between classic asp server and android app - android

I need help in this problem,I am just a student doing my university practices without any help, I have done some scripts in asp, and it is all okay but now I need to learn how can I communicate an android app which I am developing in Android Studio (first time) with an Asp Classic Server, For example a demo.asp like
<%
name=request(name)
address=request(address)
result=name&" "&address
%>
How can I send that parameters to the server and get its response in Android Studio, I hope you can help me. I would really appreciate it.

If you can figure out how to send an HTTP request to a server from your app, then the URL would look something like this:
http://example.com/test.asp?name=Hector&address=123+etc.
You showed a piece of the ASP code that processes these two parameters and concatenates them into a result string. To output that result string you would say:
response.write result
in the ASP script after the lines in your question.
Back in Java in your Android app, you would find the result from the server in the response to your HTTP request. There's a sample here that explains how to talk to a server and get a response.

Related

Res.redirect() vs res. Json(). Server for web and mobile

I am new to web development. I had a web project with EJS templating. It redirects directly from the server. Using res.redirect() . I want to create a server for web and mobile both.
Question is... When i use res.json() it sends JSON data to client side. Can work for both.
It is possible to use res.redirect() for both. Web and mobile.
Pros and cons of res.rediret and res.json
Please explain. I appreciate your suggestions in adv. Thanks.
It is possible to use res.redirect() for both. Web and mobile.
If you mean can you use res.redirect() as an alternative to res.json() then the answer is NO. res.redirect() is not an alternative to res.json. res.redirect() only sends a code and a URL back to the client, there is no data in the response. You will still need to use res.json or res.send to get the data you need. Every time you use res.redirect() you are sending a response to the client telling them to make a brand new request to another location. You're not sending any real data. The android app will not get any content till you use res.json or res.send. Redirects just tell the client go get the data from somewhere else.
Below are example responses to an android app when the server uses res.json and res.redirect
res.redirect("/user")
//Response to Android app
302 /user
The response above means what you want is located at "/user" so the mobile app will need to make a request to
res.json(user)
//Response to Android app
{
name: "Arpit Yadav",
phone: 555-555
}
res.redirect sends status code 302 (if not specified), and location (route) to browser, after which browser redirects the request to the specified location, whereas res.json sets Content-Type: application/json and sends data to the browser.
Redirection is generally meant for browser only, but, you can use it for mobile. In that case, you have to handle the logic to re-request with updated location received from server that is not recommended.
In nutshell, both have different purpose. res.redirect to move clients to different route and res.json to actually sends the data.

How to send JSON string from arduino to android device in terms of response and then decode the string on the android application?

I am currently working on a project whereby i need to send a request from an android application to my Arduino mega which in turns response back with the states of LEDs connnected to the Arduino. I have already implemented the GET request. However i need to know how to read the response back and how to send the string from the Arduino to the Android app.
Here is the code for the response:
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
client.println("{\"status\":\"ok\"}"); // <--- how to create the string?
and also how to decode it from the android application. I have seen tutorials on the internet about using InputStream to do so but am unable to understand the code. Could you please help me on this.
You have to implement a Webserver on Arduino side and use a HTTP library (i.e. OkHTTTP) to connect to the Webserver.
I used OkHTTP on Android side but you could use other libraries too.
This link is something like you are looking for. It is from my blog.
Otherwise you can use aRest. It is very simple to use. If you want to know more give a look at this link from my blog.

What is Apache-HttpClient/UNAVAILABLE error (Android, Google App Engine)?

I am confronting myself with a problem that I do not know how to interpret. I am doing a project using Android and Google App Engine. When I am trying to save information in Google App Engine's Big Table, directly from the servlet (hardcoded) - the save is performed with no problem. But when I am trying to save data from my Android device, the save is not performed and the log indicates Apache-HttpClient/UNAVAILABLE error. To be more specific:
405 55ms 0kb Apache-HttpClient/UNAVAILABLE (java 1.4)
82.155.246.249 - - [10/Jun/2013:05:20:59 -0700] "POST /servletnamehere HTTP/1.1" 405 306 - "Apache-HttpClient/UNAVAILABLE (java 1.4)" "appnamehere.appspot.com" ms=56 cpu_ms=21 cpm_usd=0.000034 app_engine_release=1.8.0 instance=00c61b117cede3f754aa1ece730dc88287a20199
I have seen that 405 HTTP error appears in the context of a POST method ( "405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form." ) => indeed, I am trying to perform add (the object is a JPA Entity) in the database using a POST method. The data I am receiving from my Android device is serialized, through an input stream (in my case, working with JSON is not an option, these are the specifications).
Also, 306 HTTP error reffers to switch proxy. While the porevious error might be a bit intuitive, this one is beyond my student knowledge.
I have followed the instructions of this tutorial (http://trumpy.cs.elon.edu/joel/sigcse2011/), which is indeed what I need, but I really cannot figure out what I did wrong. I took again the procedure, stept by step, but I don't see the flaw.
Any help will be indeed appreciated. If I should post some code, I'll gladly do it.
Best wishes,
Cropcircles
LATER EDIT:
Now I get 417 HTTP error expectation failed. I have seen that I am supposed to set a certain parameter on false, but this workaround was available only for .NET. Is there anyone who knows what's the correspondent of the following, in Java? I am really really confused.
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
This is not an answer, but is too long for a comment and may be helpful, so here goes...
First, it's hard to tell what's going on here because there is limited info. Try to post more of the logging either on the client or on the server. Go to the server console and get more info, for instance, or add debugging in the client. I'd start by trying to make the POST from a debug/testing tool like hurl.it: http://www.hurl.it/ (hurl is a nice web front end to a command line HTTP client named curl, see curl itself if you want a more advanced peek). That way you can test and poke around and make SURE your server side works as you expect with a generic client. Then build other clients (like Android).
Second, "Apache-HttpClient/UNAVAILABLE" is not an error, it's just the user-agent String -- so ignore that part. (UNAVAILABLE is where the version typically is, but some impls don't have access to the version sometimes, it seems.)
Third, the 405 response code IS an error, it means POST is not allowed at the server you are trying to POST to. That can either be because POST is not allowed at all on said server, or you're violating some security policy (such as same origin).
If it's AppEngine, first check the APP you are using and make sure it supports POST (look for info on how to do POST at AppEngine to solve, for instance: google app engine: 405 method not allowed). When you say you can do it directly from a "servlet," do you mean that a POST from a different client works? (Servlet is a server side technology, so that's a little confusing.) If so then make sure your Android app is doing the client part the same way to the same host (multipart vs urlencoded, etc).
For a little more on the security stuff, which could be involved, see this post: Google App Engine + jQuery Ajax = 405 Method Not Allowed.
I've had the same trouble and in my case It was an error due to no write permission on server side area.
I was following an android test to write on a file a value transmitted in async way via POST method.
Apache received the POST request but was not able to write the data on the file due to security permission on it.

How to check username and password in a PostgreSQL server from Android?

I am using the Android 2.2 API. I want to know how to connect to a PostgreSQL database server.
I am new to this and so have no ideas, so please help me with some sample code.
You usually don't connect directly to a database.
To achieve the results you want, you can do a RESTful request.
This means, send either a JSON string or xml file to a server(which you can program in php, ruby and what not)
I'm not going to give you sample code cause there are literally tons of code on a simple google search "android restful login"
Example tutorial
The process is usually:
Enter login credentials on android device -> send post request to server -> validate credentials to the database(postgres in this case) -> send verification back -> android device act upon verification(usually by loading a new activity as a result if logged in successfully)

ksoap2-android client throwing FileNotFoundException inside [KeepAlive]HttpsTransportSE.call()

I am attempting to create an Android (2.2) SOAP client to connect to a SQL Server 2005 XML Web Services endpoint (and of course this requires authentication). My SQL Server endpoint seems to be up and running (it's a simple function which takes a string (varchar(20)) and returns another string; the URL "https://10.1.1.20:444/dt2?wsdl" properly returns the WSDL XML. (I am not using the "?wsdl" part of the URL in my connection string; I just mention it to show the web service is working properly.)
All seems to be working well, until I am inside the call to KeepAliveHttpsTransportSE.call() (using ksoap2-android 2.5.4), and get to HttpTransportSE.class:150, where (ServiceConnection)connection.openInputStream() is called, which in turn calls connection.getInputStream() - that is what throws the FileNotFoundException.
Any idea what's happening here? What is a good next debugging step? Thanks for any input.
See the following question for more detail and the answer to the problem: Getting ParsingError, InvalidSoapActionHeader on SQL Server SOAP request

Categories

Resources