我已經修改了示例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() –