Xamarin get webservice with parameter - json

i am new with xamarin. I want to add some json data with get web service. I try like following:
var response = await client.GetAsync("myurl" + "?applicationid=" +
applicationId + "?siteid=" + siteId + "?userid=" + userId");
string responseJson = await response.Content.ReadAsStringAsync();
Debug.WriteLine("response:>" + responseJson);
But code not executed after get method.
please anyone help me.
Thanks in advance. :)

Finally got the solution, pass the values with the url itself.
var response = await client.GetAsync("mybaseurl"+"/applicationid/"1"/siteid/"5"/u‌​serid/"+25");

Related

FLUTTER API: can't use ".body"

I can't use ".body" , even if im trying to just "print(result.body);"
Im getting this error message:
String url = "https://jsonplaceholder.typicode.com/posts/1/comments";
var result = http.get(Uri.parse(url));
apiList = jsonDecode(result.body)
I have no idea how to fix, any help is welcomed.
If you need aditional information, im ready to provide
make your function async, then
var result = await http.get(Uri.parse(url));

Angular upload/download Rename/delete json file

am trying to add functions to my existing Angular project.
I need to add features like upload , download , rename or delete json file.
So I need some advice , for the easy way to do that because am new and learning typescript and angular.
Can you please guide me
Thank you
I can answer download
There are three steps you need to do
1- Issue the proper request from angular side
download(): Observable<HttpResponse<Blob>> {
return this.http.get<Blob>(someURL, {
observe: 'response',
responseType: 'blob'
});}
2- At your backend you need to set the proper headers with response, this snippet of code works with .net4.7 to return csv file contents
var contents = new byte[0]; //set your file contents at this line
var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new
ByteArrayContent(contents)};
response.Content.Headers.ContentDisposition = new
ContentDispositionHeaderValue("attachment")
{
FileName = file.Name
}
response.Content.Headers.Add("Access-Control-Expose-Headers", "Content-
Disposition");
response.Content.Headers.ContentType = new MediaTypeHeaderValue ("text/csv");
return response;
3- Finally subscribe to the http request at angular side
const result
= this.service.download()
.subscribe(res=> {
let contentDisposition = res.headers.get('content-disposition');
let filename = contentDisposition.split(';')[1].split('filename')
[1].split('=')[1].trim();
let blob = res.body;
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url);
link.parentNode.removeChild(link);
});

Uploading File using Windows.Web.Http.HttpClient - WinRT 8.1 PCL

I have a requirement of uploadng the file to Server in Win8.1 PCL project.
Windows.Web.Http.HttpClient.
I tried in Advanced Rest Client and it works fine
PFA # http://i.stack.imgur.com/N8cv5.png
I have the Code like this.
Windows.Web.Http.HttpRequestMessage request = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Post, uri);
HttpStreamContent streamContent = new HttpStreamContent(stream.AsInputStream());
streamContent.Headers.Add("Content-Type", "multipart/form-data; boundary=" + boundary);
streamContent.Headers.Add("Content-Length", stream.Length.ToString());
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"" + flKey + "\"; filename=\"" + fleNm + "\"");
request.Content = streamContent;
var httpClient = new Windows.Web.Http.HttpClient();
var cts = new CancellationTokenSource();
Windows.Web.Http.HttpResponseMessage response = await httpClient.SendRequestAsync(request).AsTask(cts.Token);
String resp = response.Content.ToString();
This is not working. Pls le me know whats wrong with the Code, why this code is not able to write the file to the server.
Thanks in Advance

JSON Parsing in Titanium App (Multidimensional array)

I want to parse a multidimensional array in Titanium.
It is something like this:-
{"nodes":
[{"node":
{
"title":"<a href=\"\/adf\/into-the-blue\">Into the Blue<\/a>",
"Teaser":"Into the Blue Teaser.",
"Knowledge":"<a href=fsdf">Americas<\/a>",
...
...
This is what I did. (It only gets the first row :( )
// url has the JSON URL.
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var response = xhr.responseText;
var resultObj = JSON.parse(response);
Ti.API.log("The Response is " + response);
Ti.API.log("THE RESULT " + resultObj);
updateBanners(resultObj);
updateTable(resultObj, catid, catregion, cattopic, listByDate);
};
xhr.open("GET", url);
xhr.send();
Many Thanks
Perhaps you are missing a piece from the parsing.
var resultObj = JSON.parse(response);
Mine usually looks like.
var resultObj = JSON.parse(response).NameOfMyRemoteFunctionResult;
I use WCF web service for my calls, so this is the type of response I get back.
This is how I was able to solve it.
//Correct Response. Gives the total number of returned Records.
resultObj.nodes.length
// and for a specific title of first row.
resultObj.nodes[0].node["title"]
alert("Total Records are :- "+ responseObjArr.nodes.length + " and the 1st Title is:- " + responseObjArr.nodes[0].node["title"]);

nodejs merge array

Im doint some nodejs fiddling with blogposts from wordpress and geotagging of theese posts. I have integrated geolite into nodejs and from wordpress i get the client id. Here is what my nodejs code looks like for now.
native.on('data',
function(data)
{
//console.log(data)
listener.sockets.emit('notification', data);
jsonstring = JSON.parse(data)
var ip = jsonstring.clientip
var geo = geoip.lookup(ip);
console.log(ip);
console.log(geo);
listener.sockets.emit('geodata', geo);
}
);
As you can see the lat / long is sent seperate from the json encoded data to the socket.
I want to merge the lat / long into "data" and sent is as 1 object. I cant figure out how to do this. i Hope someone can help me out with this.
An expando/ad-hoc property or two should suffice:
listener.sockets.emit('notification', data);
jsonstring = JSON.parse(data)
var ip = jsonstring.clientip
var geo = geoip.lookup(ip);
jsonstring.geo = geo;
// or
jsonstring.lat = geo.lat;
jsonstring.lng = geo.lng;
Add the geo information as another property of your parsed data object before emitting it:
native.on('data',
function(data)
{
var obj = JSON.parse(data)
obj.geo = geoip.lookup(obj.ip);
listener.sockets.emit('notification', JSON.stringify(obj));
}
);
You can also use
listener.sockets.emit('notification', data);
jsonstring = JSON.parse(data)
var ip = jsonstring.clientip
var geo = geoip.lookup(ip);
jsonstring['geo'] = geo;
to append the data in jsonstring
[ ] will be more helpful when we have dynamic key values