-1

404 Error Downloading an attachment in C#

Dear All.

I'm using query string to post all the necessary information in order to download the attachment like this:

url=http://mail.yahooapis.com/ya/download?oauth_consumer_key=dj0yJm..
&oauth_nonce=9142494
&oauth_signature_method=HMAC-SHA1
&oauth_timestamp=1272630753
&oauth_token=A%3DkWsST4...
&oauth_version=1.0
&oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
&realm=yahooapis.com&mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
&fid=Inbox
&pid=2
&clean=0
&inline=1

then i send the url to the following c# method

var req = HttpWebRequest.Create(url);
string Response;
using (HttpWebResponse hr = (HttpWebResponse)req.GetResponse())
{
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new
StreamReader(hr.GetResponseStream(), enc);
Response = loResponseStream.ReadToEnd();

loResponseStream.Close();
}
return Response;

but I keep getting 404. What am I doing wrong?

Appreciate your help.

by
17 Replies
  • Hi team... any help you guys can give me on this matter? I'm on a roadblock right now.
    0
  • One additional piece of information is that I'm adding the following header:

    Authorization: OAuth oauth_consumer_key="dj0yJmk9aEtXNUNWbWNzVmeD1lNA--",oauth_nonce="5928913",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1273020095",oauth_token="A="LQcnaSOboRD3vnM7eXN0_zoTFr",oauth_version="1.0",oauth_signature="8NSHbxcGTlAKQ="

    this way:

    var req = HttpWebRequest.Create(Url);
    req.Headers.Add("Authorization: OAuth " +OauthString );
    string Response;
    using (HttpWebResponse hr = (HttpWebResponse)req.GetResponse())
    0
  • I'm having the exact same problem, I'm wondering what could it be? I tried to read the response object for a more detailed message on the error but did not found any usefull.
    0
  • Anothe piece of information is that if I only send this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D

    at the URL, no headers. I get a 500 error with status code StatusCode: InternalServerError
    StatusDescription: "unable_to_get_message_info_or_part"

    but If I add the additional parameters I get: a 404 StatusCode: NotFound
    StatusDescription: "Not Found" the additional parameters are:

    mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    also I have noticed that I'm missing the oauth_session_handle however, I haven't had a need so far on my app. And if I add it I get a 404 Status Code once again

    I really need a hand with this one, this is the only thing missing in my app. Thanks.
    0
  • Carlos-
    The 404 is definitely an oauth failure. I haven't called DownloadAttachment before, but I don't think any of the APIs support passing ouath parameters in the query string. Try adding them as an Authorization header instead. If you see my code at http://github.com/ecastelli/Oauth-for-Yaho...-Social-in-.NET, take a look my buildWebRequest function in AddContactToAddressBookSocialAPI.aspx.vb. This should add the required headers for you and hopefully fix the problem.

    Let me know how it turns out.

    Eric
    0
  • Thanks for your reply Eric... I still cann't make this work. Here are the steps I'm following

    1. I buil the Url Endpoint for download with the parameters:

    http://mail.yahooapis.com/ya/download?mid=...=0&inline=1

    I stored this url on a variable called Url.

    2. Then I call Eric's function like this:

    CODE
    var req = buildWebRequest(apiAccessToken, oauthTokenSecret, Url, "GET");


    The details of the function are (I also tried without oauth_session_handle as it is on Eric's original version)

    CODE
     private System.Net.WebRequest buildWebRequest(string strAuthToken, string strAuthTokenSecret, string url, string strMethod)
    {
    OAuthBase OAuthBase = new OAuthBase();
    var webRequest = HttpWebRequest.Create(url);
    string strNonce = OAuthBase.GenerateNonce();
    string strTimestamp = OAuthBase.GenerateTimeStamp();
    string strConsumerKey = System.Configuration.ConfigurationManager.AppSettings ["ConsumerKey"];
    string strConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
    string p, h;
    Uri uri = new Uri(url);
    string strSignature = OAuthBase.GenerateSignature(uri, strConsumerKey, strConsumerSecret, strAuthToken, strAuthTokenSecret, strMethod, strTimestamp, strNonce, out p , out h);

    webRequest.Headers.Add("Authorization", "OAuth oauth_nonce=" + (char)34 + strNonce + (char)34 +
    ", oauth_timestamp=" + (char)34 + strTimestamp + (char)34 +
    ", oauth_version=" + (char)34 + "1.0" + (char)34 +
    ", oauth_signature_method=" + (char)34 + "HMAC-SHA1" + (char)34 +
    ", oauth_consumer_key=" + (char)34 + strConsumerKey + (char)34 +
    ", oauth_token=" + (char)34 + strAuthToken + (char)34 +
    ", oauth_signature=" + (char)34 + strSignature + (char)34 +
    ", oauth_session_handle=" + (char)34 + OAuthHelper.Instance.OauthSessionHandle + (char)34);


    return webRequest;
    }


    3. I try to get the bytes with this code, but on the using it raises the exception, which I catch and try to view the response which returns a "not found"... I tried several emails with attachments on several accounts and can't get it to work... please help.

    CODE
         string Response="";
    try
    {
    using (HttpWebResponse hr = (HttpWebResponse)req.GetResponse())
    {
    Encoding enc = System.Text.Encoding.GetEncoding(1252);
    StreamReader loResponseStream = new
    StreamReader(hr.GetResponseStream(), enc);
    Response = loResponseStream.ReadToEnd();

    loResponseStream.Close();
    }
    } catch (WebException ex)
    {
    HttpWebResponse response = ex.Response as HttpWebResponse;
    }

    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    return encoding.GetBytes(Response);



    QUOTE (Eric @ May 6 2010, 04:48 AM) <{POST_SNAPBACK}>
    Carlos-
    The 404 is definitely an oauth failure. I haven't called DownloadAttachment before, but I don't think any of the APIs support passing ouath parameters in the query string. Try adding them as an Authorization header instead. If you see my code at http://github.com/ecastelli/Oauth-for-Yaho...-Social-in-.NET, take a look my buildWebRequest function in AddContactToAddressBookSocialAPI.aspx.vb. This should add the required headers for you and hopefully fix the problem.

    Let me know how it turns out.

    Eric
    0
  • Bummer. I was hoping this would do the trick. Are you using the same OAuthBase assembly referenced in this code? Are you getting user auth through the oAuth process as I use in my example? I am assuming yes in both cases, but just want to make sure. If you are doing both, I wonder if Yahoo! has not yet upgraded the download API to use Oauth (it is a seperate API from the typical Yahoo! mail API and they just recently upgraded this to use Ouath). Have you tried BBAuth instead?

    Eric
    0
  • Download API definitely supports OAuth and also all APIs support query string requests. We first need to close down on the error. The 500 error is returned by Ymail webservice and 404 error is an OAuth error as Eric mentioned. Are you sure the mid is correct? I don't see an issue in the way you are sending requests but not sure on the values.

    --R



    QUOTE (Eric @ May 6 2010, 02:20 PM) <{POST_SNAPBACK}>
    Bummer. I was hoping this would do the trick. Are you using the same OAuthBase assembly referenced in this code? Are you getting user auth through the oAuth process as I use in my example? I am assuming yes in both cases, but just want to make sure. If you are doing both, I wonder if Yahoo! has not yet upgraded the download API to use Oauth (it is a seperate API from the typical Yahoo! mail API and they just recently upgraded this to use Ouath). Have you tried BBAuth instead?

    Eric
    0
  • QUOTE (yMailJanitor @ May 6 2010, 02:51 PM) <{POST_SNAPBACK}>
    Download API definitely supports OAuth and also all APIs support query string requests. We first need to close down on the error. The 500 error is returned by Ymail webservice and 404 error is an OAuth error as Eric mentioned. Are you sure the mid is correct? I don't see an issue in the way you are sending requests but not sure on the values.

    --R



    Good to know.

    Carlos - Make sure you are going through the whole Ouath process as I have detailed and that you are using the same OauthBase assembly I have in my sample (I have found some that don't work - especially the VB.NET example I found.). Also, can you confirm the MID is getting pulled based on a call to ListMessages? If you are successfully calling ListMessages there's a good chance you are functioning properly on Ouath. If your not calling ListMessages, where are you getting the MID from?

    I would think the MID being bad would return a 500 error and not a 404 though, so it sounds like your signature may be bad. Yahoo! is generally pretty good at returning errors in the response header on the 404 errors. Try using Effetech's HTTP Sniffer to view the response headers (http://www.effetech.com/sniffer/). You can also see them if on your catch statement if you catch your exception as an HTTPWebException rather than a simple Exception (e.g., catch ex as HTTPWebException....).

    Eric
    0
  • Thanks for the reply, I'm getting the mid, fid and pid from calls to the yahoo web service. One question so a request like this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
    &mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    as long as it i signed with all the appropriate parameters (incluindg fid, mid, pid, clean and inline) should work right? also... what happens if I'm missing the:

    realm and oauth_session_handle I didn't had a need to use them on my other requests... will they make a difference? I tried with them but no luck either... and if they are needed will they need to be part of the url for the signature process?

    Thanks so much guys for the help... I know I'm close to the solution and this will help other.


    QUOTE (yMailJanitor @ May 6 2010, 02:51 PM) <{POST_SNAPBACK}>
    Download API definitely supports OAuth and also all APIs support query string requests. We first need to close down on the error. The 500 error is returned by Ymail webservice and 404 error is an OAuth error as Eric mentioned. Are you sure the mid is correct? I don't see an issue in the way you are sending requests but not sure on the values.

    --R




    QUOTE (yMailJanitor @ May 6 2010, 02:51 PM) <{POST_SNAPBACK}>
    Download API definitely supports OAuth and also all APIs support query string requests. We first need to close down on the error. The 500 error is returned by Ymail webservice and 404 error is an OAuth error as Eric mentioned. Are you sure the mid is correct? I don't see an issue in the way you are sending requests but not sure on the values.

    --R
    0
  • I found the problem... that endpoint: http://mail.yahooapis.com/ya/download is a bit tricky.... the problem was that I was not signing the ENTIRE REQUEST including the parameters appropriately. Once I did it... then it was good...

    Thanks so much to everyone that stepped to help me. I owe you guys one.

    QUOTE (Carlos @ May 6 2010, 04:31 PM) <{POST_SNAPBACK}>
    Thanks for the reply, I'm getting the mid, fid and pid from calls to the yahoo web service. One question so a request like this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
    &mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    as long as it i signed with all the appropriate parameters (incluindg fid, mid, pid, clean and inline) should work right? also... what happens if I'm missing the:

    realm and oauth_session_handle I didn't had a need to use them on my other requests... will they make a difference? I tried with them but no luck either... and if they are needed will they need to be part of the url for the signature process?

    Thanks so much guys for the help... I know I'm close to the solution and this will help other.
    0
  • Happy you found the solution!

    Eric

    QUOTE (Carlos @ May 6 2010, 05:05 PM) <{POST_SNAPBACK}>
    I found the problem... that endpoint: http://mail.yahooapis.com/ya/download is a bit tricky.... the problem was that I was not signing the ENTIRE REQUEST including the parameters appropriately. Once I did it... then it was good...

    Thanks so much to everyone that stepped to help me. I owe you guys one.
    0
  • Nice guys. Good Job.

    Happy Coding :)Eric
    0
    • Aug 22, 2012
    hello,
    now i am working on this issue and facing same problem, could you please tell me the complete success request example code,
    note: i am using OAuthBase.

    QUOTE(Carlos @ 6 May 2010 6:05 PM)
    I found the problem... that endpoint: http://mail.yahooapis.com/ya/download is a bit tricky.... the problem was that I was not signing the ENTIRE REQUEST including the parameters appropriately. Once I did it... then it was good...

    Thanks so much to everyone that stepped to help me. I owe you guys one.

    QUOTE (Carlos @ May 6 2010, 04:31 PM) <{POST_SNAPBACK}>
    Thanks for the reply, I'm getting the mid, fid and pid from calls to the yahoo web service. One question so a request like this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
    &mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    as long as it i signed with all the appropriate parameters (incluindg fid, mid, pid, clean and inline) should work right? also... what happens if I'm missing the:

    realm and oauth_session_handle I didn't had a need to use them on my other requests... will they make a difference? I tried with them but no luck either... and if they are needed will they need to be part of the url for the signature process?

    Thanks so much guys for the help... I know I'm close to the solution and this will help other.
    0
    • Aug 28, 2012
    Hello, how are you?

    please :(, i am facing same problem....please post your successful sample complete web request with query string & Authorization header....
    and what are the "entire request" to get it work..


    waiting.....


    QUOTE(Carlos @ 6 May 2010 6:05 PM)
    I found the problem... that endpoint: http://mail.yahooapis.com/ya/download is a bit tricky.... the problem was that I was not signing the ENTIRE REQUEST including the parameters appropriately. Once I did it... then it was good...

    Thanks so much to everyone that stepped to help me. I owe you guys one.

    QUOTE (Carlos @ May 6 2010, 04:31 PM) <{POST_SNAPBACK}>
    Thanks for the reply, I'm getting the mid, fid and pid from calls to the yahoo web service. One question so a request like this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
    &mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    as long as it i signed with all the appropriate parameters (incluindg fid, mid, pid, clean and inline) should work right? also... what happens if I'm missing the:

    realm and oauth_session_handle I didn't had a need to use them on my other requests... will they make a difference? I tried with them but no luck either... and if they are needed will they need to be part of the url for the signature process?

    Thanks so much guys for the help... I know I'm close to the solution and this will help other.
    0



  • \r
    \r
    QUOTE( @ 28 Aug 2012 12:00 AM)
    \r
    Hello, how are you?

    please :(, i am facing same problem....please post your successful sample complete web request with query string & Authorization header....
    and what are the "entire request" to get it work..


    waiting.....


    \r
    \r
    QUOTE(Carlos @ 6 May 2010 6:05 PM) \r
    I found the problem... that endpoint: http://mail.yahooapis.com/ya/download is a bit tricky.... the problem was that I was not signing the ENTIRE REQUEST including the parameters appropriately. Once I did it... then it was good...

    Thanks so much to everyone that stepped to help me. I owe you guys one.

    \r
    \r
    QUOTE (Carlos @ May 6 2010, 04:31 PM) <{POST_SNAPBACK}> \r
    Thanks for the reply, I'm getting the mid, fid and pid from calls to the yahoo web service. One question so a request like this:

    http://mail.yahooapis.com/ya/download?oaut...mer_key=dj0yJm..
    &oauth_nonce=9142494
    &oauth_signature_method=HMAC-SHA1
    &oauth_timestamp=1272630753
    &oauth_token=A%3DkWsST4...
    &oauth_version=1.0
    &oauth_signature=xHoxC7UxEZdCOmvqMRVyyoIXnvI%3D
    &mid=1_6717_AK2niGIAAIRCS9cjEQnnsAU2p38
    &fid=Inbox
    &pid=2
    &clean=0
    &inline=1

    as long as it i signed with all the appropriate parameters (incluindg fid, mid, pid, clean and inline) should work right? also... what happens if I'm missing the:

    realm and oauth_session_handle I didn't had a need to use them on my other requests... will they make a difference? I tried with them but no luck either... and if they are needed will they need to be part of the url for the signature process?

    Thanks so much guys for the help... I know I'm close to the solution and this will help other.
    0
  • same problem here. If i use json-endpoint i get 500 error

    if i use http get i get 404 error. yahoo mail api document is one of the worst. its been 2 years since some body got it to work, they still have no code samples for c#

    0

Recent Posts

in Yahoo! Mail Web Services API