What is wrong with a HttpBasicAuthenticator - restsharp

I am trying to use a RestSharp coding sample in order to connect to MailGun. In the code below, please see:
client.Authenticator = new HttpBasicAuthenticator("XXX","key-yyyyyyyyyyyyyyyyyyyyyyy");
What is wrong with the HttpBasicAuthenticator? VisualStudio says:
Severity Code Description Project File Line Error CS0246 The type or
namespace name 'HttpBasicAuthenticator' could not be found (are you
missing a using directive or an assembly reference?) xTest_MailGun
Note: Visual Studio2015 Community; RestSharp 105.2.3
This is the code:
RestClient client = new RestClient();
client.BaseUrl = new Uri("https://api.mailgun.net/v3");
client.Authenticator = new HttpBasicAuthenticator("XXX","key-yyyyyyyyyy");
RestRequest request = new RestRequest();

Authenticators are in a different namespace than RestClient, you're likely just missing a using statement at the top. Do you have this?
using RestSharp;
Add this right below it:
using RestSharp.Authenticators;

Related

'Restclient' does not contain a 'BaseUrl' Error

I am working on Asp.net core project. trying to send mail using mailgun. used mailgun C# code given in https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-api
But getting an error "RestClient" does not contain a "BaseUrl" error.
I saw your Comment Code, I think You have to Change this to get the Output.
var client = new RestClient();
client.BaseUrl = "https://api.mailgun.net/v3";
client.Authenticator = new HttpBasicAuthenticator("api", "YOUR_API_KEY");
var request = new RestRequest();
request.Resource = "/address/validate";
request.AddParameter("address", "address#domain.com");
//Change Resource and AddParameter as per need
var response = client.Execute(request);
dynamic content = Json.Decode(response.Content);
var client = new RestClient(new Uri("yourbaseurl"));

How to use ToListAsync() in .net core web api

First of all I am beginner, using asp.net core web API (3.1), so my question is in the below code why not able to call the toListAync method.
While calling toListAsync method getting error. Can anyone suggest some tips to solve the problem. I was trying to call the method as an async with dapper.
Error:- Task<IEnumerable<Owner>> does not contain a definition for toListAsync and no accessible extension method toListAsync accepting a first argument of type Task<IEnumerable<Owner>> could be found (are you missing a using directive or an assembly reference?)
public async Task<IAsyncEnumerable<Owner>> GetCustomerAsync()
{
IAsyncEnumerable<Owner> owners = null;
var query = "select * from tbl_Owner";
using (var sqlCon = new SqlConnection())
{
var k = await sqlCon.QueryAsync<Owner>(query).toListAsync();
return owners;
}
}
Did you forget to import the corresponding package?
Try to add:
using System.Data.Entity;
For EF Core ,you can add the following assembly reference:
using Microsoft.EntityFrameworkCore;

Cadence Java client - Worker.Factory cannot be resolved

I am following the samples given in the java client sdk. Specifically
https://github.com/uber/cadence-java-samples/blob/master/src/main/java/com/uber/cadence/samples/hello/HelloWorkerSetup.java
Compiler is not able to resolve
Worker.Factory
I have tried to look in the client SDK code but I cannot seem to get past this error.
Has something changed in how workflows have to be registered?
Thanks
Sanjay
ClientOptions tOptions = ClientOptions.newBuilder().setHost(serverHostName).setPort(serverPort).build() ;
WorkflowServiceTChannel tChannel = new WorkflowServiceTChannel(tOptions);
WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setDomain(serverDomain).build();
WorkflowClient wfClient = WorkflowClient.newInstance(tChannel,clientOptions);
WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().build();
WorkerFactory factory = WorkerFactory.newInstance(wfClient,factoryOptions);

Error when uploading file to SP - could not find file: c:\windows\system32\inetsrv\

I'm uploading a file to a SharePoint Document library using the following code:
string fileToUpload = oFile.PostedFile.FileName;
using (SPSite oSite = new SPSite(spsite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList library = oWeb.Lists[documentLibraryName];
using (FileStream fs = new FileStream(fileToUpload, FileMode.Open))
{
//more logic here
This works fine in my dev environment, but when I move it to QA, I get the following error when try to upload a file:
System.IO.FileNotFoundException:
Could not find file 'c:\windows\system32\inetsrv\file_to_upload'.
I have googled around, and it seems like I may need to use PostedFile.InputStream instead of PostedFile.Name.
But if set fileToUpload equal to oFile.PostedFile.InputStream, then I am not able to use this bit of code anymore:
using (FileStream fs = new FileStream(fileToUpload, FileMode.Open))
I would like to still use this code as I need to access fs.name later on in my code.
Any idea how I could get this problem resolved?
Give it a try, this might be helpful
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/96f81cea-12b2-46f0-83ec-64c7fd9532cd/using-aspnet-fileupload-control-in-sharepoint-2010-announcement-list-newformaspx?forum=sharepointdevelopmentprevious

Issues performing a query to Solr via HttpClient using Solr 3.5 and HttpClient 4.2

I am trying to query my local Solr server using HttpClient and I cannot figure out why the parameters are not being added to the GET call.
My code for doing this is:
HttpRequestBase request = new HttpGet("http://localhost:8080/solr/select");
HttpParams params = new BasicHttpParams();
params.setParameter("q", query);
params.setParameter("start", String.valueOf(start));
params.setParameter("rows", String.valueOf(rows));
request.setParams(params);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
return stringToStreamConversion(is); //500 error, NullPointerException, response is empty
I have tried to return several things in hopes of seeing what I would get and trying to figure out where the problem was. I have finally realized that I was only getting back the http://localhost:8080/solr/select when I returned
return request.getURI().toURL().toString();
I cannot figure out why the parameters are not getting added. If I do
return request.getQuery();
I get nothing back...any ideas? Thanks for the help in advance!
From what I have seen you are not able to associate your paeans with the request.
So, instead of creating a new HttpParams object and associating it with request, can you try the following approach ?
httpCclient.getParams().setParameter("q", query");
....
The simpler option is to use the approach I used in HTTPPostScheduler, like this:
URL url = new URL(completeUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("type", "submit");
conn.setDoOutput(true);
// Send HTTP POST
conn.connect();