Windows Phone HttpWebRequest non ASCII Uri - windows-phone-8

I've the same problem in that thread How to handle HttpWebRequest redirect with non-ascii characters and I've spend two days searching how to solve it but I really get no answer.
This is the exception message:
[net_WebHeaderInvalidControlChars]
Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.7.60408.0&File=System.Net.dll&Key=net_WebHeaderInvalidControlChars
Parameter name: name
Could anyone help me please?
var wbr = WebRequest.CreateHttp(new Uri("http://www.10youtube.com/IowY8e6DaQIT-T53f8d4d6a64e6ec06e0b42a8c662cc05T-Tmp4T-TmediumT-T18TTT.mp4", UriKind.Absolute));
wbr.AllowAutoRedirect = true;
wbr.Method = "GET";
wbr.AllowReadStreamBuffering = false;
wbr.BeginGetResponse(ar =>
{
var req = (HttpWebRequest)ar.AsyncState;
var res = req.EndGetResponse(ar);
}, wbr);

Did you try some :
System.EscapeUriString()
Look at the documentation here :
http://msdn.microsoft.com/en-us/library/system.uri.escapeuristring%28v=VS.95%29.aspx

Related

FormatException (FormatException: Unexpected character (at character 1)

I am trying to get data from a json from a link and decode it to display data in a calendar, so it worked fine until this error appears in this line
dynamic jsonAppData = convert.jsonDecode(data.body);
Which trows this:
Exception has occurred. FormatException (FormatException: Unexpected
character (at character 1) <!doctype html><base href="https://accou... ^ )
I don't really know why it is caused, I searched for solutions but I didn't find anything for my case.
I hope you can help me.
Future<List> getDataFromGoogleSheet() async {
Response data = await http.get(
Uri.parse(
"https://script.google.com/macros/s/AKfycbybaFrTEBrxTIni8izFKMQYNNAe7ciVMlqF0OUHyWujjRR2AQ8zDyQzh96tleRKMHSN/exec"),
);
dynamic jsonAppData = convert.jsonDecode(data.body);
final List<Meeting> appointmentData = [];
for (dynamic data in jsonAppData) {
var recurrence = data['byday'];
Meeting meetingData = Meeting(
eventName: data['subject'],
from: _convertDateFromString(data['starttime']),
to: _convertDateFromString(data['endtime']),
background: Colors.grey.shade800,
recurrenceRule: 'FREQ=DAILY;INTERVAL=7;BYDAY:$recurrence;COUNT=10',
);
appointmentData.add(meetingData);
String notes = data['notes'];
}
return appointmentData; }
Your response body is not of json type.
You should check your request before
You can't parse the json because you have to authenticate with google first. If you call the page in the browser, where you are not logged in with Google, then you are redirected to the login page of Google. And my guess is this page is parsed, not the json.

Google script null object - don't understand why

I'm starting to write Google scripts to automatize certain tasks, and here I'm stuck on a problem I can't figure out by myself. I must say I'm neither an expert in app scripts (yet) nor in javascript.
Here is my problem. I make a call to a (private) REST API to retrieve some data. I get the result, parse it to get a Json object. Then I want to write some properties in a spreadsheet. For some reason, I can't get to manipulate nested objects.
Say I have a list of this json payload :
{
id: 2146904633,
status: "in_progress",
success_probability: 99,
amount: "0.0",
decision_maker: "Bob Mauranne",
business_contact: {
id: 2142664162,
nickname: "NIL",
}
}
EDIT : I made a mistake with the code I pasted (businessContact was not declared, instead a variable bc was declared).Thanks for the comment :) The code below is correct now, but still doesn't work.
I get it like with this (overly simplified) code :
var response = UrlFetchApp.fetch(url);
var dataAll = JSON.parse(response.getContentText());
var data, businessContact;
for (i = 0; i < dataAll.length; i++) {
data = dataAll[i];
businessContact = data.business_contact;
Logger.log(data.status);
Logger.log(businessContact);
Logger.log(businessContact.id);
}
My problem is that when I call businessContact.id I get the error "TypeError: unable to read property id from null object". And I don't understand since I can see the content from businessContact : either from the log call or from the debugger, it's definately not null.
It seems to happen only on nested objects, because on simple properties, I don't have any error. And I have the same problems on all nested objects, whatever json payload I've tried so far...
I searched on the internet for a solution but found none. It probably is very basic, but I can't get it to work.
Any idea ?
You never define "businessContact" that your using in the logger. You define "bc" but not "businessContact". If you changed it to Logger.log(bc.id) it should work.
Here is a trimmed down version of what your trying to do also.
function getJSON() {
var url = "your url";
var response = UrlFetchApp.fetch(url).getContentText();
var data = JSON.parse(response)
data.forEach(function(item) {
Logger.log(item.business_contact.id)
})
}
Heres an example pulling weather data.
function myFunction() {
var url = "https://www.aviationweather.gov/gis/scripts/TafJSON.php";
var response = UrlFetchApp.fetch(url).getContentText();
var data = JSON.parse(response)
data.features.forEach(function(feature) {
Logger.log(feature.properties.id)
})
}
I finally found the solution. This code is in a loop, sometimes the object business_contact is null and I hadn't seen it :|
Clearly I should stop working late in the evening when I learn a new technology ...
My bad, sorry for the noise, and thanks for the answers and comments guys.

IOS - How to handle return calls from a RESTful service API

I am using an API to have users create an account within my app.
Now I am able to generate the URL required in objective-C to submit the values and in the API documentation it has the return numbers that will confirm to me what has happened.
My question is how do I relay that information to the user of the app?
The return call is shown to me in a HTML page as plain text.
Any ideas?
Thanks in advance.
///////
2012-10-03 12:24:31.557 Multi Web[72631:15203] Dictionary list - {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Length" = 26;
"Content-Location" = "signup.php";
"Content-Type" = "text/html";
Date = "Tue, 02 Oct 2012 23:24:32 GMT";
P3P = "policyref=\"/w3c/p3p.xml\", CP=\"ALL CURa ADMa DEVa OUR IND UNI COM NAV INT STA PRE\"";
Server = "Apache/2.2.14 (Ubuntu)";
Status = "200 OK";
TCN = choice;
Vary = "negotiate,Accept-Encoding";
"X-Limit-Key-Limit" = 10000;
"X-Limit-Key-Remaining" = 9992;
"X-Limit-Key-Reset" = 236;
"X-Limit-User-Limit" = 320;
"X-Limit-User-Remaining" = 319;
"X-Limit-User-Reset" = 3600;
"X-Powered-By" = "PHP/5.3.2-1ubuntu4.14";
I got this in my console so I now, I have created the account succesfully.
In the middle it says Status = "200 OK";
How do I use that particular line? If I can hook up a UIAlertView to that then i am where I want to be.
Cheers.
I'm not sure if your situation is related to this question. According to docs from the getPocket API you are using, i see the following:
According to apple docs, the default HTTP method is GET. What you need to do is check the response headers from the API. So what you need to do is change your httpMethod to HEAD like so:
NSMutableURLRequest *modReq = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"www.somesite.com/?something"]];
[modReq setHTTPMethod:#"HEAD"];
Then you can read the values from the header with something like so:
NSURLResponse* response = // the response, from somewhere
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
You can then get the response values, and tell the user whats up accordingly.
It's called designing and creating a user interface.
You send a request to the server and get a response. Your job is to examine the response, recognise what it means, and tell the user in an appropriate way what the response meant. Since the user is not an expert in parsing html, showing the html would almost always be entirely inappropriate.
For a user entering a username and password correctly, the appropriate response is usually that the user can now access the site.

How to POST JSON using Adobe Flex

I'm trying to POST some JSON data using Adobe Flex but having some problems. I'm now getting the error message "A URL must be specified with useProxy set to false", even though I do have useProxy set to false.
Update : code below is now working.
var data:Object = new Object();
data.ipaddr = ipaddr.text;
data.netmask = netmask.text;
data.gatewayip = gatewayip.text;
var jsonData:String = JSON.stringify(data);
var s:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
// URL needs to be specified on a separate line, call is unreliable otherwise
s.url = Utils.getBaseURL() + '/cgi-bin/setnetworksettings';
s.contentType = "application/json";
s.resultFormat = mx.rpc.http.HTTPService.RESULT_FORMAT_TEXT;
s.method = "POST";
s.useProxy = false;
s.addEventListener("result", httpResult);
s.addEventListener("fault", httpFault);
s.send(jsonData);
What do you mean by "doesn't seem to do anything"? No response from the server? Fault instead of result? Which one? Help us help you with more details, just stating it doesn't work is not enough.
First of all, be sure that your URL is correct, you should get something in the service result handler OR fault handler, anything. That should help you diagnose and fix any URL problems if any.
Then for the JSON part, you object is not a valid JSON (no escaping and : instead of =), try sending this first: {"ipaddr":"10.1.1.1"}.
From here it should be easy: as F4L stated, you can use the JSON class to encode a real object directly to JSON.
Hope that helps

WebRequest Caching Windows Phone 7

From what I understand, the HttpWebRequest class always cache the downloaded data. Now I don't mind this, but after a throughly reparsing the same URL through HttpWebRequest during the app duration, I've noticed that the data becomes corrupted (as in the downloaded JSON data becomes unparsable). After rebooting the Phone Emulator, it all goes smoonthy until it happens again.
Now I am just wondering if it possible to turn off the caching in HttpWebRequest.
Here is some of the code I am using to make a httpwebrequest call:
var request = (HttpWebRequest)WebRequest.Create(string.Format(uri));
request.BeginGetResponse(a =>
{
var response = request.EndGetResponse(a);
var responseStream = response.GetResponseStream();
using (var sr = new StreamReader(responseStream))
{
string json = sr.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//Newtonsoft.Json.Linq;
JObject artistObject = JObject.Parse(json);
//...etc
});
}
}, null);
}
A common technique to get around this caching is to add an parameter to the query string that is incremented on successive calls. This thread discusses the silverlight behaviour in more detail, and covers some server handling you can look at too if you have that control.
WebClient Caching Problem
With that said, have you been able to produce a simple repro of the corruption you're experiencing? It might be worth getting that looked into.