Custom API service class:
using System.IO;using System.Net;
using System.Text;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.File;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System.Threading.Tasks;
final class Dax_ApiMultipleHeaders
{
public static void main(Args _args)
{
str url = "https://xkcd.com/info.0.json",responsejson;
WebException exception;
System.Net.HttpWebRequest webrequest;
CLRObject webResponse =null;
System.Exception ex;
System.Net.HttpWebResponse response;
System.Net.WebHeaderCollection httpHeader;
str response1;
str byteStr;
System.Byte[] byteArray;
System.IO.Stream stream,Datastream;
System.IO.StreamReader streamReader;
System.Text.Encoding utf8;
ApiTable apiTable;
//webrequest = System.Net.WebRequest::Create("URL") as System.Net.HttpWebRequest;
//webRequest.Method = 'POST';
// webRequest.KeepAlive = true;
// webRequest.Timeout = maxInt();
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
httpHeader = new System.Net.WebHeaderCollection();
webResponse = Sys tem.Net.WebRequest::Create(url);
webrequest = webResponse;
webrequest.set_keepalive(true);
webrequest.set_ContentType("application/json");
webrequest.set_method("get");
webrequest.set_Headers(httpHeader);
webResponse = webrequest.GetResponse();
Datastream = webResponse.getResponseStream();
streamReader = new System.IO.StreamReader(Datastream);
responsejson = streamReader.ReadToEnd();
info(responsejson);
DAx_JsonDataContract object = formjsonserializer::deserializeObject(ClassNum(DAx_JsonDataContract),responsejson);
//List listData = new List(Types::Class);
//listData = object.parmData();
//ListEnumerator listEnumerator = listData.getEnumerator();
// DAx_JsonDataContract jsonDataContract = listEnumerator.current();
apiTable.Month = object.parmMonth();
apiTable.Year = object.parmYear();
apiTable.Day = object.parmday();
apiTable.Number = object.parmNumber();
apiTable.SafeTitle = object.parmsafeTitle();
apiTable.insert();
}
catch(Exception::CLRError)
{
ex = CLRInterop::getLastException().getBaseException();
error(ex.get_Message());
streamReader.Close();
Datastream.Close();
webResponse.close();
}
}
}
Key Points: We need to create contract class which are presenting in API URL those are parameters.
No comments:
Post a Comment