ln.json/JSONWebRequest.cs
2017-11-03 13:13:09 +01:00

45 lines
915 B
C#

using System;
using sharp.extensions;
using System.Net;
using sharp.webclient;
using System.IO;
using System.Collections.Generic;
namespace sharp.json
{
public class JSONWebRequest
{
private static JSONParser jsonParser = new JSONParser();
public static JSON Call(string url){
return Call(url, null);
}
public static JSON Call(string url, JSON request)
{
return Call(url, request, null);
}
public static JSON Call(string url, JSON request, IDictionary<string,string> headers)
{
HttpRequest req = new HttpRequest(url);
if (request != null){
byte[] rbody = request.ToString().toBytes();
req.RequestStream.Write(rbody,0,rbody.Length);
}
if (headers != null)
{
foreach (string hname in headers.Keys)
{
req.setHeader(hname, headers[hname]);
}
}
HttpResponse response = req.Send();
return jsonParser.Parse(response.ContentText);
}
}
}