Successfully using the Mantis SOAP API (aka "MantisConnect") from C#, I can successfully read an issue and also get the download_url field.
When trying to download the attachment by something like this:
using (var request = new WebClient())
{
request.Credentials = new NetworkCredential("username", "password");
return request.DownloadData(mantisAtt.download_url);
}
it "downloads" a HTML page with the login screen instead of the binary attachment content.
So my question is:
How can I programmatically download an attachment for an issue in Mantis?
I was on the completely wrong track. Instead of following the download URL being returned I now use the function mc_issue_attachment_get and everything works as expected.
So to solve, do not download from the URL but simply use the intended SOAP API function.
(I found the solution after posting my question to the "mantisbt-soap-dev" mailing list and got a fast reply)
Related
If a Gmail user sends an email with an inline image, then the image will be stored on Google's servers, and the email's HTML will include code like this...
<img src="https://mail.google.com/mail/u/0?lot-sof-stuff-here" alt="Yoda.png" width="300" height="300">
If you're logged in to Google, you can visit this link in your browser, and you'll be redirected to the image, whose URL looks like...
https://gm1.ggpht.com/lots-of-stuff-here-too
If you're not logged in, you'll get sent to Google's sign-in page
I want to download the image from my C# code, but have two problems, first I need to get past the Google sign-in, and second I need to handle the redirect.
I tried the following...
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = true;
request.Credentials = new NetworkCredential("gmailaddress", "password");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
...but the response object has a ResponseUri for the Google sign-in page, which sounds like it ignored the credentials I passed in.
Anyone any idea how I can do this? Thanks
Update Following the comment by SiKing, I don't think tis is a Gmail issue as such, I think the storage being used here is more general Google storage. The problem is I can't find any Google API for accessing that storage. If anyone knows of any, please point me in the right direction.
I have some code that connects to an HTTP API, and is supposed to get an XML response. When the API link is placed in a browser, the browser downloads the XML as a file. However, when the code connects to the same API, HTML is returned. I've told the API owner but they don't think anything is wrong. Is there a way to capture the downloaded file instead of the HTML?
I've tried setting the headers to make my code look like a browser. Also tried using WebRequest instead of WebClient. But nothing works.
Here is the code, the URL works in the browser (file downloaded) but doesn't work for WebClient:
WebClient webClient = new WebClient();
string result = webClient.DownloadString(url);
The code should somehow get the XML file instead of the page HTML (actually the HTML doesn't appear in the browser, only the file).
The uri that you access may be a HTML page that have its own mechanism (like generating the actual download address which may be dynamically generated by the server and redirecting to it, in order to prevent external linking access) to access the real file.
It is supposed to use a browser background browser core like CefSharp to run the HTML and its javascript to let it navigate, and probably you may want to hook the download event to handle the downloading.
I think you need to add accept header to the WebClient object.
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.Accept] = "application/xml;q=1";
string result = webClient.DownloadString(url);
}
Thank you all for your input. In the end, it was caused by our vendor switching to TLS 1.2. I just had to force my code to use 1.2 and then it worked.
I would like to programmatically retrieve thumbnails of documents from SharePoint. What I'm trying to do is the following:
document.GetImagePreviewUrl(width, height, clientType);
This just returns an empty ClientResult. I am not sure what to enter as clientType value.
I have also tried to use this method programmatically (by using WebClient and downloading the file). But that just returns a 403 response.
The possible solutions I see here are the following:
Figure out what to enter as clientType and retrieve the preview url that way.
Figure out how to tell SharePoint that I am authorized programmatically (using WebClient and headers for instance).
I do need some help regarding these two options, I am not sure where to start since both options aren't well documented.
I've figured out a way to do it, the 403 error was caused because sharepoint had no idea who I was. After some research and fiddling I found out that the request you send to the preview page contains an authentication cookie. This cookie can be generated by code using this piece of code:
// Create an authentication cookie which we can send with the request so sharepoint knows who we are.
var authCookie = credentials.GetAuthenticationCookie(new Uri(imageUrl));
client.Headers.Add(HttpRequestHeader.Cookie, authCookie);
// Download the image data to a byte array
image = client.DownloadData(imageUrl);
I am working with twilio.com api in C#.net. C# code calls the phone number I have given:
string accountSid = "AC5xxxxxxxxxfdb0cf485d52ce";
string authToken = "57fxxxxxxxxx1xxx71a";
var client = new TwilioRestClient(accountSid, authToken);
var request = new CallListRequest();
var callList = client.ListCalls(request);
var options = new CallOptions();
options.Url = "http://demo.twilio.com/docs/voice.xml";//
options.To = "+919876123456";
options.From = "+15163425887";
var call = client.InitiateOutboundCall(options);
MessageBox.Show(call.Sid);
I call my phone through above given code, picking up the call connects me to the xml file (a twiML file) mentioned in options.Url and I listen the message and .mp3 file mentioned in voice.xml. Now I want to replace this xml file with my custom xml file placed in a server. For testing purpose I created the exact copy of voice.xml and placed it into my server. So I change the url property to:
options.Url="http://productionserver.com/voice.xml";
After making this change when I pick the phone, it says "Application error has occurred" and call ends.
Has anyone worked with twilio and experienced such problem ? Is there any step that I am missing other than just creating an xml file ?
Twilio evangelist here.
First I'd suggest checking to see if anything got logged in your App Monitor. I suspect you will see Twilio has logged a 500 error there.
If you are trying to serve the raw XML file from IIS, then your probably running into the issue that IIS won't serve an XML file from a POST request, which is the default HTTP Method Twilio uses to request the Url.
There are a couple of work-arounds for this:
You can set the Method property on the CallOptions to GET which tells Twilio to make its request using the HTTP GET method OR
Since this is static XML you are serving, you cold use http://twimlbin.com to host the TwiML
Hope that helps.
Im looking for solution how can I upload some file using http request. I got the idea that I'll transfer my files by post and on PHP side I'll put files on the server.
How doin this?
var client = new System.Net.WebClient();
client.UploadFile(address, filename);
See UploadFile on MSDN.
Well I'd try the simplest possible thing that might work to start with - WebClient.UploadFile:
WebClient client = new WebClient();
client.UploadFile(url, file);
Of course, you'll have to write appropriate PHP code to handle the upload...
One more approach is to upload file via browser and handle upload request/response with Fiddler. After that, you can write exact request using HttpWebRequest via C#.