This API is working through postman.
I am trying the same thrid-party API from my application like below:
string requestUrl = string.Empty;
string result = string.Empty;
System.Net.WebClient client = new System.Net.WebClient();
using (client)
{
requestUrl = "https://api.fyndx1.de/hogwarts/aggregators/api/v1/config1/authToken";
client.QueryString.Add("username", "tester");
client.QueryString.Add("password", "pwd123");
result = client.DownloadString(requestUrl);
}
403 error is coming. I tried to add User agent to header parameters after querystring but no use.
client.Headers.Add("User-Agent: Other");
Any help is appreciated. Thanks.
Related
How do we call GitLab API using access token to get all the commits in a project.
I am getting unauthorized error.
string Url = "http://xxxxxx/DevOps/WebApp1.git/repository/commits";
using(var client = new WebClient()) //WebClient
{
client.BaseAddress = Url;
//client.UseDefaultCredentials = true;
client.Headers.Add("Content-Type:application/json"); //Content-Type
client.Headers.Add("Accept:application/json");
client.Headers[HttpRequestHeader.Authorization] = "Bearer xxxxx";
var commits_List = client.DownloadString(Url);
}
The documentation clearly states:
You can use a personal access token to authenticate with the API by passing it in either the private_token parameter or the Private-Token header.
You are doing neither of them.
Remove your authorization header and replace it with this:
client.Headers["Private-Token"] = "xxxxx";
Try:
https://gitlab.com/api/v4/projects/{your_project_id}/repository/commits?private_token={your_private_token}
I am trying to get data from an API using python 'urllib.request'. My requests sometime need to post json data.
My network is behind a proxy
When i try to get the data using C# code, everything works great:
WebClient wc = new WebClient();
WebProxy wp = new WebProxy("{IP}", 8080);
wc.Proxy = wp;
var request = "https://{API address and params}";
Uri serviceUri = new Uri(request);
string download = wc.DownloadString(serviceUri);
My python code is:
import urllib
address = "https://{API address and params}"
req = urllib.request.Request(address)
req.set_proxy("{IP}:8080", "http")
response = urllib.request.urlopen(req)
My python code throws a 400 error code exception - 'bad request'
What am i doing wrong?
I want to post variables from C# to a php-script on my webserver. I tried this following code from the internet but it returns this error message:
Error: The remote server returned an error. (406) Not Acceptable.
The c# part:
string URI = "https://myserver.com/post.php";
string myParameters = "param1=value1¶m2=value2";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
MessageBox.Show(HtmlResult);
}
The php part:
<?php
if(isset($_POST['param1']) && isset($_POST['param2']))
{
$user = $_POST['param1'];
$date = $_POST['param2'];
echo $user . ' : ' . $date;
}
?>
I have tested it with a test post server and it works but it won't work on my server.
Your backend service is saying that the response type it is returning is not provided in the Accept HTTP header in your Client request.
Source: What is "406-Not Acceptable Response" in HTTP?
I have consumed the web service in windows application, when pass the request to get response getting an error.
I have used WSE 2.0 to pass the credentials.
public string GetResponse(string sPersonnelAreaCode, string sCompanyCode)
{
try
{
WebReference.RIL_STAR_HCM_QueryEmployeeDetails_serviceagent objService1 = new WebReference.RIL_STAR_HCM_QueryEmployeeDetails_serviceagent();
WebReference.fetchEmployeeListRequestEmployeeList[] objReqs = new WebReference.fetchEmployeeListRequestEmployeeList[1];
WebReference.fetchEmployeeListRequestEmployeeList objReq1 = new WebReference.fetchEmployeeListRequestEmployeeList();
WebReference.fetchEmployeeListResponseEmployeeList[] objResponse = new WebReference.fetchEmployeeListResponseEmployeeList[0];
DataSet dsresult = new DataSet();
objReq1.PersonnelAreaCode = sPersonnelAreaCode;
objReq1.CompanyCode = sCompanyCode.ToString();
UsernameToken token = new UsernameToken("***", "***", PasswordOption.SendPlainText);
objService1.RequestSoapContext.Security.Tokens.Add(token);
objReqs[0] = objReq1;
//In the below line getting that error
objResponse = objService1.fetchEmployeeList(objReqs);
}
}
Can anyone please help me?
This kind of error usually comes when the report server path is not proper. Double check your ReportServerUrl
Also refer Report viewer Error message "client found response content type of '' but expected 'text xml' The request failed with an empty response."
Try setting the ContentType:
objReq.ContentType = "text/xml";
Assuming you're using HttpWebRequest..
I am trying to post a share on Jive using the /Shares REST API in .net using C#. However I am not able to do this and getting the following error:
"The remote server returned an error: (400) Bad Request."
Following is the code which I have written:
string response = string.Empty;
using(WebClient client = new WebClient())
{
string strJiveShareURL = "https://<JiveURL>";
strJiveShareURL += "/api/core/v3/shares";
var SharedJSON = new AddShareJSON
{
participants = new string[] {"https://<JiveURL>/api/core/v3/people/{username}" },
shared = "https://<<Content URL to be shared>>",
content= new Content
{
type = "text/html",
text = "This is a test share from SharePoint to Jive"
}
};
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string shareJSON = serializer.Serialize(SharedJSON);
Console.WriteLine("Setting Credentials:");
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("UID:PWD"));
client.Headers[HttpRequestHeader.Authorization]= "Basic " + credentials;
client.Headers[HttpRequestHeader.Accept] = "application/json";
client.Headers[HttpRequestHeader.ContentType] = "application/json";
//BypassCertificateError();
response = client.UploadString(strJiveShareURL, "POST", shareJSON);
Console.WriteLine("Response:" + response);
Console.ReadLine();
}
and following is the JSON which is created for posting the share:
{
"content": {
"type":"text/html",
"text":"This is a test share from SharePoint to Jive"
},
"participants": ["https://<<Jive URL>>/api/core/v3/people/<<username>>"],
"Shared":"https://<<URL of the Content To be Shared>>"
}
Please let me know if there is anything which I have been doing incorrectly.
I figured this out myself, I was getting the error because I was passing an invalid URI object to the shared parameter of the Share REST endpoint. The shared parameter requires a content URI in the form of
http://[[JiveURL]]/api/core/v3/contents/[[ContentID]]
Earlier I was trying to pass URLs external to Jive resulting in the bad request error.