我已经修改了示例Demo以尝试发送json对象而不是字符串。该网站将其视为价值[对象]字符串而不是Json文本。我需要改变什么。新手如何使用scriptsharp将Json信息发送到Web服务
namespace DemoScript {
// [Imported]
// [IgnoreNamespace]
public sealed class Person
{
public string FirstName;
public string LastName;
}
[GlobalMethods]
internal static class HelloPage {
static HelloPage() {
// Add script that runs on startup as the script is loaded into
// the page
Element helloButton = Document.GetElementById("helloButton");
Person p = new Person();
helloButton.AddEventListener("click", delegate(ElementEvent e) {
InputElement nameTextBox = Document.GetElementById("nameTextBox").As<InputElement>();
p.FirstName = nameTextBox.Value;
p.LastName = "Surname";
XmlHttpRequest xhr = new XmlHttpRequest();
// xhr.Open(HttpVerb.Get, "/HelloService.ashx?name=" + nameTextBox.Value.EncodeUriComponent());
xhr.Open(HttpVerb.Get, "/HelloService.ashx?name=" + p);
...
}
}
}
如果我传递p.FisrtName,它将按预期工作。
你或许应该编码查询字符串参数。使该text.EncodeUriComponent() –