I have the following URL
http:actionname.php?user=username&password=pwd&sender=no&audio_file=somefilehere
I want to send an audio file along with the above parameters.
Is it possible to send an audio file as a request parameter?
Thanks in advance...
You can send the name of a file, but not the file itself. URL lengths are limited, practically to about 2000 characters. Theoretically they may be a bit longer, but this is not supported on all browsers. See this answer.
If the file is publicly available, and the file name is a URL itself, the server may fetch the file later.
If you want to send a file, consider having a POST request with the file content in it.
As usually, you will send anything as request to web server, the file content will be transferred as internals of HTTP message (POST parameters as file name, and content separately) outgoing from you to the server, until it finished (it is TCP session and it won't be break up while data is streaming), it could be considered as "request" to web server.
Theoretically, you could send something via URL (HTTP GET request), but you could develop some kind of transport data-over-HTTP-GET protocol to send escaped binary data chunks as GET parameters. It is possible :)
Even sending (uploading) file via POST request also no so plain as submitting form with usual POST parameters, you should use multipart/form-data encoding in the form and special treatment on the server side for that.
It is not good, but not so weird as transmitting data via URL, you could send some data within GET request to the server, look here for more.
Related
Overview:
I currently have a fully functioning mobile application that communicates with a Java server running on Windows via WebSockets. The ServerEndpoint is running off of an AWS machine. The Java server is a ClientEndpoint running on a private network, and there can be multiple app users at any given time that are also ClientEndpoints.
I currently have everything working properly when it comes to sending String messages back and forth, as the ServerEndpoint is maintaining the Java server Session along with the mobile application Sessions. Almost all communication is initiated via the mobile applications at which time a JSON String is sent to the Java server session to be able to maintain which mobile application session should receive the return message.
I am now trying to implement functionality to be able to send PDF files via binary messages from the Java server to the mobile applications in the same fashion. The mobile applications are developed using Codename One, and they do not provide the ability to increase the maximum binary message size, so I seem to be limited to 8kb (8,192 bytes) per binary message. This is fine as I am sending multiple binary messages and rebuilding the file within the mobile app.
I currently have this working in the simplest case where there is only one mobile application user at a time requesting a PDF file.
Current Flow:
App A sends JSON message to ServerEndpoint which then forwards message to Java server A. Java server A sends JSON message back to ServerEndpoint which forwards message back to App A. The JSON objects contain the session id to send the messages back to. The ServerEndpoint needs to know which App Session to send messages to that come from the Java server.
When it comes to binary messages, App A sends a String message to the ServerEndpoint which then forwards message to Java server A. Java server A now needs to send multiple binary messages back to the ServerEndpoint which ALL must get forwarded to App A for the file to be rebuilt properly. This is the part that I'm not sure how to handle. It currently works fine if there is only one App session, but if multiple App sessions were to request files at the same time, it would not work properly.
Problem:
When sending String messages, it is easy enough to pass the callback mobile application session id as part of the JSON object back and forth to ensure the correct mobile application session gets the response. When it comes to sending the binary messages, what is the best way to guarantee that if users A and B request a file at the same time, that user A gets the file he/she requested and user B gets the file he/she requested?
You should be able to track the session without having to pass a session ID. For example, see this sample web service endpoint.
Notice how you can pass a Session object as the first parameter with the #OnMessage annotation.
You can use this to know who you're talking to.
One other small point/question. Your statement "The mobile applications are developed using Codename One, and they do not provide the ability to increase the maximum binary message size," seems to suggest that other platforms do allow you to set a maximum binary size on the client. AFAIK this is not part of the WebSocket spec, and isn't implemented by any browser. What other implementations do allow you to set the max size?
EDIT In response to your refinement of the question:
There are multiple ways to skin this cat. One thought is that you only need to chunk the "last mile" (between the middleman and the client). Since the middleman and the end server are JavaEE servers, you have control over the buffer size, and could potentially send the full file in one shot (within reason). Then just do the chunking in the middle server, which will know which client he is dealing with.
Another option is to create your own pseudo protocol. You're returning byte arrays, but you could choose to allocate the first n-bytes of each chunk to contain metadata, which the middleman would parse out. This metadata could be used to tell the middleman which client the chunk is destined for.
Zip the files you want to send and send it via binary, in server unzip it to get the data, i think size is not of a problem(havent tried Codename One though). If it is then you could send chunks of binary data that is structured to a jason object with a type and serial number that you can check to find the type of file you are sending and the number of chunk of the file it is. the flow will be like
get chuncks -> Json Object (Type="PDF", SerialNumber="1", Data="Binary data converted to String") -> zip the json object -> send to server. Do the reverse in server.
I'm attempting to use Nexmo.com to send and receive text messages. Sending works fine, but I am having some issues receiving messages.
My issue is with the Callback URL and what format that page should be in. Nexmo's documentation is here and says this
Inbound Message
If you have purchased long virtual numbers, you will need to set up a CallBack URL for inbound to which we will send a request for each incoming message. Nexmo will be expecting response 200 OK, or it will retry.
The request parameters sent via a GET (default) to your URL include the following parameters.
Am I missing something extremely simple? Is there somewhere that I haven't found with an example of a Callback URL page? Thanks for any help!
Edit: For clarification, I'm using Nexmo's provided java library, but since their api is all built around URL's the java program simply visits a URL to send the message. Here
are their provided libraries
Not sure if I've understood your question.
Generally, if you want to receive messages, you have to setup a service on your server, with a callback url, say http://api.example.com/sms/
Then you setup this callback url in Nexmo. After that, Nexmo will access your server through the callback url, and send parameters via GET method.
And your server receives those info, and response 200 to Nexmo.
I have gone thru javadocs of URLEncoder and URLDecoder. Then got more inquisitive. Consider the server as tomcat.In any webapplication whenever we submit
the form , server converts the forms fields into urlencoded fields and when we do request.getParamter("fieldName"). Server again decode it with URLDecoder.
Is that correct? Does server do it or browser? Simlary when we type any url in address bar same stuff happens? If server or browser does that
when we require to encode or decode the request paramter explicitly with the help of URLEncoder and URLDecoder? Though these are basic questions but could not find these anwers clearly.
In any webapplication whenever we submit the form , server converts the forms fields into urlencoded fields and when we do request.getParamter("fieldName").
No. The browser does that.
Server again decode it with URLDecoder. Is that correct?
Yes.
Does server do it or browser?
The browser.
If server or browser does that when we require to encode or decode the request parameter
explicitly with the help of URLEncoder and URLDecoder?'
I don't know what that means but it's still the browser. You only need to encode the request parameters if you are sending the request from application code. You don't need to decode them at all if you're running in a servlet container: it will do that for you.
While it is true that browser does encode a URL before passing it off to the web server but there may not be a browser involvement all the time.
e.g. your server app might be making a REST based call and passing some data in a simple GET request. And then if you don't encode it on your server it may become garbled when receiver decodes it.
Therefore it is highly recommended to always encode the URL before sending it off in your server code.
I was wondering what the preferred way of sending an image to a webserver from an android application?
I've seen people
opening up sockets and send the actual image data.
base64 encoding it and sending it as a string.
What is the preferred way? Can someone post some examples as well.
Thanks
You could try writing it to an xml file as a base64 string then send it an parse the file on the server and decode the string to an image.
An HTTP Post is probably the easiest way, sending it as multi-part form data. Makes it easier to receive as well (a bog standard web server can handle it!)
I have an application made in Java for Android platforms, and I need to send quite a lot of data, the data I am sending is the previous weeks SMS messages received and sent. That includes the following data:
Sent by Phone number
Sent by Name
Sent to Phone number
Sent to Name
Time sent
Message
And you can imagine this data can be really big for some people so I need a way to minimize/encrypt it on one side, and then using an HTTP request I can send it over to my server, and decrypt this data with PHP. What is the best method to do this? What size limit does HTTP POST have?
I think you should zip+encrypt(say, using aes) the data on Android side before sending the data to your server and decrypt+unzip it on the server side.
Post size depends on the config on the server side -> What is the size limit of a post request?.
p.s. why would anyone want to send all their sms messages to your server? :)
You'll want to send the data using an HTTP POST. The limit on the HTTP POST size depends on the server receiving the data. For example a PHP server has the post_max_size property that (I think) by default is 16M. In terms of encryption start by making sure the request is being sent over HTTPS.
Do you have Gzip option turn on in your Apache HTTPD server?
This way the web server will compress and serve slightly packed files to and bro your browser.