One or more errors occurred. (Unexpected character encountered while parsing value: <. Path '', line 0, position 0.)
this MyFatoorahRESTApi.cs
public class MyFatoorahRESTApi
{
private static HttpClient _httpClient = null;
private SystemMode lIVE;
public string BaseAddress { get; set; }
public string MerchandUserName { get; set; }
public string MerchandPassword { get; set; }
private static SystemMode _systemMode { get; set; }
static readonly object padlock = new Object();
public static HttpClient httpClient
{
get
{
if (_httpClient == null)
{
lock (padlock)
{
if (_httpClient == null)
{
_httpClient = new HttpClient();
}
}
}
return _httpClient;
}
}
public MyFatoorahRESTApi(bool isSandBox=true)
{
_systemMode = isSandBox ? SystemMode.TEST : SystemMode.LIVE;
}
public MyFatoorahRESTApi(SystemMode lIVE)
{
this.lIVE = lIVE;
}
public async Task<TokenResponse> GetTokenAsync()
{
var response = string.Empty;
var apiTokenRequest = new TokenRequest()
{
Grant_Type = "password",
UserName = MerchandUserName,// "[email protected]",
Password = MerchandPassword// "api12345*"
};
var apiUrl = string.Format("{0}/{1}", BaseAddress, "bearer wcaLFUGNxXc_P3yhdOG4YvpKpomCR1bMwfXDeoFnjWLjGnLgNXgnetm1Zwf1ha8LRqNfFNsUNDSW262VCyNC9EV4Vrk6gCvOwyR5PGl9PxYecODb8K0vKMQHAytkZdl2X2EG7IZnAKD2LNilY42Ry3A8GNbz4ylpyZxiuD3fXYNV8L3ZMplpsXjoQ4cpP-K076nDeefVS4fO-Gc-GGaJgGXElRY7U9Vy7t3sE0hzWZPPeQf1m0yeBS4oRQtG47nKu5AweZbytVB60XgyvoVewa-PY5cfVQSKheG4RqCXOK_6wYJDObpEmjIwH2tyScYrz34MrIvzovW-qzzcy");
var pairs = new List<KeyValuePair<string, string>>();
pairs.Add(new KeyValuePair<string, string>("grant_type", "password"));
pairs.Add(new KeyValuePair<string, string>("username", apiTokenRequest.UserName));
pairs.Add(new KeyValuePair<string, string>("password", apiTokenRequest.Password));
var httpContent = new FormUrlEncodedContent(pairs);
var request = String.Format("grant_type=password&username={0}&password={1}",
apiTokenRequest.UserName, apiTokenRequest.Password);
StringContent content = new StringContent(request, System.Text.Encoding.UTF8, "application/json");
response = await UseHTTPClient(content, apiUrl, "POST", null);
var apiTokenResposne = JsonConvert.DeserializeObject<TokenResponse>(response);
return apiTokenResposne;
}
public async Task<TransactionResponse> GetOrderStatusRequestAsync(string paymentId, TokenResponse token)
{
var url = string.Format("{0}/{1}/{2}", BaseAddress, "ApiInvoices/Transaction", paymentId );
var response = await UseHTTPClient(null, url, "GET", token);
var apiTokenResposne = JsonConvert.DeserializeObject<TransactionResponse>(response);
return apiTokenResposne;
}
public async Task<InvoiceResponse> CreateInvoice(TokenResponse tokenResponse, InvoiceRequest apiInvoiceRequest)
{
var url = string.Format("{0}/{1}", BaseAddress, "ApiInvoices/CreateInvoiceIso");
var request = JsonConvert.SerializeObject(apiInvoiceRequest);
StringContent content = new StringContent(request, System.Text.Encoding.UTF8, "application/json");
var response = await UseHTTPClient(content, url, "POST", tokenResponse);
var apiInvoiceResponse = JsonConvert.DeserializeObject<InvoiceResponse>(response);
return apiInvoiceResponse;
}
private async Task<string> UseHTTPClient(StringContent httpContent, string url, string method, TokenResponse token)
{
if (token != null)
{
httpClient.BaseAddress = new Uri(BaseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
}
HttpResponseMessage httpResponse = null;
if (method == "POST")
{
httpResponse = await httpClient.PostAsync(url, httpContent).ConfigureAwait(false);
}
if (method == "GET")
{
httpResponse = await httpClient.GetAsync(url, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
}
//if (httpResponse.IsSuccessStatusCode)
var response = await httpResponse.Content.ReadAsStringAsync();
return response;
}
}
}
I think the error from above code
plz help me for resolv this problem