I have trying to posting a pdf file to rest api and I get a 500 internal server error. The code works for a word doc and its also works in debug mode in a visual studio 2015 but fails in production. At this point I am not sure if its a code issue. Help, don't have much hair left.
I have tried both IE and chrome no difference. I have tried other document file types does are fine, but PDF. Do I have to do something different for PDF other then the content type?
private bool Request_login_mydgsi_ca(out HttpWebResponse response)
{
response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://login.mydgsi.ca/WebAPI/Attachment?aboutType=Candidate&referenceID="+Candidate_id.Trim()+"&attachmentTypeID=Resume&Name=Resume&expirationDate=1900/01/01&Note=Candidate%20Resume");
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
string client_id = ConfigurationManager.AppSettings["client_id"].ToString();
string secret_id = ConfigurationManager.AppSettings["secret_id"].ToString();
ERApplyForJobs ePosition = new ERApplyForJobs(client_id, secret_id, "");
string tokenAPI = ConfigurationManager.AppSettings["APIToken"].ToString();
string secruityToken = ePosition.getSecurityToken(tokenAPI);
request.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + secruityToken );
request.ContentType = "multipart/form-data; boundary=---224842443399224314204538";
request.KeepAlive = true;
request.Method = "POST";
request.ServicePoint.Expect100Continue = true;
string contentType = MimeMapping.GetMimeMapping(fileName);
string body = @"---224842443399224314204538
Content-Disposition: form-data; name=""""; filename=""" + fileName + @"""
Content-Type: " + contentType + @"<!>" + fullFileName + @"<!>---224842443399224314204538--";
WriteMultipartBodyToRequest(request, body);
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
response = (HttpWebResponse)e.Response;
}
catch (Exception)
{
if (response != null) response.Close();
return false;
}
return true;
}