I am using Push Sharp to send push notification to iOS and Android clients. I need to send a List of strings, but not sure how can I achieve this? Do I need to send it with payload? Can someone show me code to do this?
For iOS sample code is given:
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"../../../Resources/PushSharp.Apns.Sandbox.p12"));
//Extension method
push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "radint123?"));
push.QueueNotification(new AppleNotification()
.ForDeviceToken("b06d5462020a01703f6c740f8de77d7450878739ec2954775db5411d0f3f17d7")
.WithAlert("Hello World!").WithBadge(i)
.WithSound(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"../../../Resources/sound.caf")));
Yes, you have to send it with payload like this (VB.Net Code):
Dim appleNotif As New AppleNotification
'Define other properties here
Dim notiPayLoad = New AppleNotificationPayload()
notiPayLoad.AddCustom("key1", "value1")
notiPayLoad.AddCustom("key2", "value2")
appleNotif.Payload = notiPayLoad
push.QueueNotification(appleNotif)
Related
How do I access what has been posted by a client to my classic ASP server?
I know that there is the Request.Forms variable, but the client's request was not made using a Form.
The client request's body is just a string made using a standard POST statement.
Thanks
You need to read request bytes if content type of request sent by client is not form data. In this case, request is not a form-data that is accessible through name-value pairs so you cannot use Request.Form collection. I suggest investigate the BinaryRead method.
Reading posted data and convert into string :
If Request.TotalBytes > 0 Then
Dim lngBytesCount
lngBytesCount = Request.TotalBytes
Response.Write BytesToStr(Request.BinaryRead(lngBytesCount))
End If
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
Hope it helps.
Update #1:
With using JScript
if(Request.TotalBytes > 0){
var lngBytesCount = Request.TotalBytes
Response.Write(BytesToStr(Request.BinaryRead(lngBytesCount)))
}
function BytesToStr(bytes){
var stream = Server.CreateObject("Adodb.Stream")
stream.type = 1
stream.open
stream.write(bytes)
stream.position = 0
stream.type = 2
stream.charset = "iso-8859-1"
var sOut = stream.readtext()
stream.close
return sOut
}
To get the JSON string value just use CStr(Request.Form)
Works a treat.
In Classic ASP, Request.Form is the collection used for any data sent via POST.
For the sake of completeness, I'll add that Request.QueryString is the collection used for any data sent via GET/the Query String.
I would guess based on the above that even though the client is not a web browser, the Request.Form collection should be populated.
note: all of this is assuming the data being sent is textual in nature, and that there are no binary uploads (e.g. pictures or files) being sent. Update your question body if this is an incorrect assumption.
To test, write out the raw form data and see what you have - something along the lines of:
Response.Write(Request.Form)
Which with a regular web page will output something like
field=value&field2=value2
If you get something along those lines, you could then use that as a reference for a proper index.
If you do not get something like that, update your question with what you tried and what you got.
I am trying so long to write into my database the simplest data using javascript to do so, but i tried so many ways it seems i can't do it, i was writing in my firebase just this three values coming from a submit button in my webpage:
var user = document.getElementById("usuario").textContent;
var msn = $("#usermsg").val();
var d = new Date();
var t = d.getTime();
firebase.database().ref('chat_room/'+user+'/'+t).set({
message : msn,
sender : server,
receiver : user
});
firebase database result:
-KwRbHu2cHj5rXo1GDeH
message: "5"
receiver: "ipm9KUXcReSGHzFCFxWbwyU61Bb2"
sender: "server"
and this is working just fine, but i tried to change it like this and it never work again:
var chatFire = firebase.database().ref().child('chat_room').child(user).push();
console.log('push: '+chatFire);
chatFire.set({
message:msn,
sender:server,
receiver:user,
hora:t
});
and the result it's just the same as the code above this one, doesn't take the key "hora", just the first three, and even if i change a letter from the key for example "sender" to "senderx" it doesn't take this as well just the other two:
firebase result
-KwRbJrbymfOs0jPOUwe
message: "hghg"
receiver: "ipm9KUXcReSGHzFCFxWbwyU61Bb2"
It seems that it's taken a format from somewhere like a pojo or something, but there is nothing in my entire code that is controlling this data, please help!
Just to add more info my Rules in FirebaseDatabase are allowing write and read for all, so that is not the problem.
thanks in advance!!
I can send a parameter from as3 to asp. And I can get a value from db. But unfortunatelly I cant combine both of them. Is it possible to send a ID parameter from as3 to asp where I want to make a sql query on a db. Then query result will return back to the as3. Users can login with their id number. And they can see their own datas on the as3 application. My sample codes are given:
I can send values with these codes:
var getParams:URLRequest = new URLRequest("http://www***********/data.asp");
getParams.method = URLRequestMethod.POST;
var paras:URLVariables = new URLVariables();
paras.parameter1 = ""+userID;
getParams.data = paras;
var loadPars:URLLoader = new URLLoader(getParams);
loadPars.addEventListener(Event.COMPLETE, loadCompleted);
loadPars.dataFormat = URLLoaderDataFormat.VARIABLES;
loadPars.load(getParams);
function loadCompleted(event:Event):void
{
trace("sent")
}
I can get values from db with these codes:
var urlLoader:URLLoader =new URLLoader();
urlLoader.load(new URLRequest("http://www***********/data.asp"));
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
function onXMLLoad(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
var scrptVars:URLVariables = new URLVariables(loader.data +"");
returnParameter= scrptVars.LINK0;
high.HighScore.text = returnParameter + "";
}
What is the logic of combining them?
Sory for my English level :)
To combine the second one into the first, you just need to read the URLLoader's data property (which is the response from the server) on the loadCompleted method (same as you're doing in the onXMLLoad method):
function loadCompleted(event:Event):void
{
trace("sent and received", loadPars.data);
high.HighScore.text = loadPars.data.LINK0;
}
The COMPLETE event for a URLLoader fires once the request has received a response. If your server adds data to that response, it can be found in the data property of the URLLoader.
So to summarize, sending and receiving can be done all in one operation with one URLLoader. The data you send to the server, is found in the URLRequest object passed to the URLLoader, the data that comes back from that request, is found in the data property of the URLLoader object (but only after the COMPLETE event fires).
I have done below and it works well,
// send ObjectData to client
((IServiceCapableConnection)iConnection)
.invoke(clientSideMethod, someObjectData);
But I have no idea that If I want to send compressed ByteArrayData, which mehod should I invoke?
Could someone give me some idea?
You can use the method that you're already using or some of the other available methods such as onImageData. Just make sure you use the ByteArray class and have AMF3 selected for your NetConnection when you connect.
Here is an AS file that shows how to use the onImageData method: http://red5.googlecode.com/svn/flash/trunk/player4/src/Main.as
Well I am wondering how I can achieve to post a multipart in chunked mode. I have 3 parts, and the files which can be big so must be sent in chunks.
Here what I do :
MultipartEntity multipartEntity = new MultipartEntity() {
#Override
public boolean isChunked() {
return true;
}
};
multipartEntity.addPart("theText", new StringBody("some text", Charset.forName("UTF-8")));
FileBody fileBody1 = new FileBody(file1);
multipartEntity.addPart("theFile1", fileBody1);
FileBody fileBody2 = new FileBody(file2);
multipartEntity.addPart("theFile2", fileBody2);
httppost.setEntity(multipartEntity);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpClient httpClient = new DefaultHttpClient(params);
HttpResponse httpResponse = httpClient.execute(httppost);
On the server side, I do receive the 3 parts but the files for example are not chunked, they are received as one piece... basically total I see 4 boundaries appearing only : 3 --xxx, 1 at the end --xxx-- .
I thought the override of isChunked would do the trick but no... ;(
Is what I am trying to do feasible ? How could I make that work ?
Thanks a lot.
Fab
To generate a multipart body chunked, one of the part must have it size unavailable. Like a part that is streaming.
For example let assume your file2 is a really big video. You could replace the part of your code:
FileBody fileBody2 = new FileBody(file2);
multipartEntity.addPart("theFile2", fileBody2);
wtih that code:
final InputStreamBody binVideo = new InputStreamBody(new FileInputStream(file2), "video/mp4", file2.getName());
multipartEntity.addPart("video", binVideo);
since now the third part is an InputStream instead of File, your multipart HTTP request will have the header Transfer-Encoding: chunked.
Usually any decent server-side HTTP framework (such as Java EE Servlet API) would hide transport details such as transfer coding from the application code. just because you are not seeing chunk delimiters by reading from the content stream does not mean the chunk coding was not used by the underlying HTTP transport.
You can see exactly what kind of HTTP packets HttpClient generates by activating the wire logging as described here:
http://hc.apache.org/httpcomponents-client-ga/logging.html