
Hi...
Can anyone suggest me how to convert the following API call in javascript to C# code (WebClient only):
function GetData() {
formType = Xrm.Page.ui.getFormType();
$.ajax({
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Authorization", "Bearer " + token);
},
type: "Get",
crossDomain: true,
cache: false,
url: "some url here", //Search API
data: { qry: search, from: 1, to: 100, format: 'json', ctrycode: 1 },
dataType: "json",
success: function (data) {
if (formType == 1) {
debugger;
getSearchData(data);
}
else if (formType == 2) {
getUpdateData(data);
}
},
error: function (error, readyState, textStatus, statusCode) {
getErrorDetails(error, readyState, textStatus, statusCode);
}
});
}
}
I tried the following code but it is giving error: {"Cannot send a content-body with this verb-type."}. This error says that you can not use content body with method GET. But my requirement is to use GET only.
GetDatafromAPI getData = new GetDatafromAPI();
getData.qry = "search";
getData.from = "1";
getData.to = "100";
getData.format = "json";
getData.ctrycode = "1";
string url1 = "intouch-api.linkmobility.com/.../search";
DataContractJsonSerializer objSerialization1 = new DataContractJsonSerializer(typeof(GetDatafromAPI));
MemoryStream objStream1 = new MemoryStream();
objSerialization1.WriteObject(objStream1, getData);
string data1 = Encoding.UTF8.GetString(objStream1.ToArray(), 0, (int)objStream1.Length);
WebClient webClient1 = new WebClient();
webClient.Headers["Authorization"] = "Bearer " + token;
webClient.Encoding = Encoding.UTF8;
var response1 = webClient.UploadString(url1, "GET", data1);
I want to retrieve data in WebClientResponse so that i can pass it to another function in C# code.
Please help
*This post is locked for comments
I have the same question (0)Hi Needhi,
Refer the link below.
msdn.microsoft.com/.../mt742424.aspx
It shows the web API sample using c#.