Why won't attatched files created using tcpdf not work except in gmail? - tcpdf

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers = "From: $from";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . strip_tags($content) . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<2;$x++)
{
$data = chunk_split($att[$x]);
$message .= "Content-Type: {\"application/pdf\"};\n" . " name=\"$name[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";

IMO the solution is NOT to fix your code.
My advice would be to use one of the numerous very good email libraries that are already available for PHP, such as SwiftMailer or PHPMailer. Encoding email is an extremely tricky task due to all of the nuances of the various email clients/sites and these libraries have already been tested quite thoroughly with pretty much all of them. Existing libraries also include functionality that will help reduce the likelihood that the emails get marked as spam at the destination.

Related

how to make a http post with param and json payload at same time with openedge requestBuilder

I need to send a post to an url with parameters and with a json payload.
In Postman, for example, I made this:
post http://address.com?key=As8941a1891389123812312381923 and in the body put the json in RAW format. On header I just put a Content-type application/json, and it works fine.
In openedge I tryed this:
oJson = new JsonObject;
oJson:add('...blablabla',payloadData).
assign cURL = 'http://address.com?key=As8941a1891389123812312381923'.
oHttpClient = ClientBuilder:Build():Client.
Assign oRequest = RequestBuilder:Post(cURL,oJson)
:Content-type('application/json')
:AcceptJson()
:Request.
Assign oResponse = oHttpClient:Execute(oRequest).
But, I got a 403 error from the server.
it seems the problem is when I try to send ?key=xxxx parameter with the URL and also a json payload at same time, or, I made a mistake in cUrl formation.
In other kind of posts I made (and that works ok) without a json payload, when has some parameters, usually I have to send the parameters separately, like this:
ASSIGN id = trim("db=" + trim(db) + "&lg=" + trim(lg) + "&sh=" + trim(sh) +
"&sxml=" + trim(argumentos))
htmlRequest = trim(id).
oRequestBody = new String(htmlRequest).
oRequest = RequestBuilder:Post(trim(cURL),oRequestBody)
:AcceptHtml()
:Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
how to send both parameter "?key=...." and a json payload at same time with openedge RequestBuilder?
Does anybody can help?
Thanks in advance
I have checked your request - with and without the JSON entity - and in both cases the query string is part of the POST.
I'm using OpenEdge 12.2 now and the result is:
POST /?key=As8941a1891389123812312381923 HTTP/1.1
Host: address.com
Content-Type: application/json
Content-Length: 16
Accept: application/json
{"blablabla":42}
Here's my test routine:
BLOCK-LEVEL ON ERROR UNDO, THROW.
USING OpenEdge.Core.* FROM PROPATH .
USING OpenEdge.Net.* FROM PROPATH .
USING OpenEdge.Net.HTTP.* FROM PROPATH .
USING OpenEdge.Net.HTTP.Filter.Writer.* FROM PROPATH .
USING OpenEdge.Net.HTTP.Filter.Payload.* FROM PROPATH .
USING Progress.Json.ObjectModel.* FROM PROPATH .
DEFINE VARIABLE oJson AS JsonObject NO-UNDO .
DEFINE VARIABLE cUrl AS CHARACTER NO-UNDO.
DEFINE VARIABLE oHttpClient AS IHttpClient NO-UNDO .
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO .
DEFINE VARIABLE oMessageBody AS ByteBucket NO-UNDO .
DEFINE VARIABLE oBodyWriter AS MessageWriter no-undo.
DEFINE VARIABLE cRequest AS CHARACTER NO-UNDO.
/* *************************** Main Block *************************** */
oJson = NEW JsonObject() .
oJson:Add ('blablabla', 42).
ASSIGN cURL = 'http://address.com?key=As8941a1891389123812312381923'.
oHttpClient = ClientBuilder:Build():Client.
ASSIGN oRequest = RequestBuilder:Post(cURL,oJson)
:ContentType('application/json')
:AcceptJson()
:Request
oMessageBody = NEW ByteBucket()
oBodyWriter = RequestWriterBuilder:Build(oRequest)
:WriteTo(oMessageBody)
:Writer.
oBodyWriter:Open().
/* writes the message's contents into the message body */
oBodyWriter:Write(oRequest).
oBodyWriter:Close().
cRequest = GET-STRING(oMessageBody:GetBytes():Value, 1) .
MESSAGE cRequest VIEW-AS ALERT-BOX .

Response Headers not setting Ruby on rails

I'm using devise for authentication . and i want to set some custom response and request headers . I'm trying to do response.headers['HEADER NAME'] = 'HEADER VALUE' but it's not setting .
Can anyone help . plus i want to get / set request and response headers in every request
I don't know why response.headers['HEADER NAME'] = 'HEADER VALUE' was not working , while it's mentioned in ruby document also . But my headers made work with
headers['Uid'] = new_auth_header['uid']

Arduino Ethercard ENC28J60 Posting data not working

I've been trying to post data to my Apache web server at home with no luck.
I can see that the server receives the request in the log file but headers are all messed up and the server cannot process the request.
Arduino code used to send the data are as follows:
char website[] PROGMEM = "10.0.0.200";
ether.hisip[0] = 10;
ether.hisip[1] = 0;
ether.hisip[2] = 0;
ether.hisip[3] = 200;
byte sd = stash.create();
stash.print("?Controller=");
stash.println(String(Controller));
stash.print("&Sensor=");
stash.println(String(Door1SensorId));
stash.save();
Stash::prepare(PSTR("POST http://$F/addDoorData.php HTTP/1.1" "\r\n"
"Host: $F" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, website, stash.size(), sd);
ether.tcpSend();
The result that I receive on the server looks as follows:
POST http://\x95\x1f\x93\xcf\x93\xdf\x93\xeb\x01#\x91q\x05P\xe0)/0\xe0B\...." 400 572 "-" "-"
request failed: error reading the headers.
If anyone can help it would be greatly appreciated.

Asana API Adding an Attachment via cURL/PHP

Experiencing difficulty trying to successfully add an attachment to a task using cURL/PHP.
$data = array("file" => "#$filename");
$headers = array("Authorization: Basic " . base64_encode($asana_api_key) . ":"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://app.asana.com/api/1.0/tasks/$task_id/attachments");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
Assume $filename, $asana_api_key, and $task_id are set properly. Should be fairly straightforward... but for some unknown reason I get the following response:
{"errors":[{"message":"Server Error","phrase":"19 snobby warthogs cheer busily"}]}
Oddly enough, running this request using curl command line works perfectly. I've tinkered with this for hours now to no avail.
Any ideas as to what the issue may be?
This was a bug on our end, and should now be fixed. It had to do with the way curl was sending the filename, namely, as the entire path to the file. Browsers typically send only the basename (without the directory). We now apply the same logic ourselves if we get a full path for our local name, and it seems like it works, but your case may be different.
I'd certainly appreciate knowing if it works for you now.

404 Error when trying to post a file topic

I am trying to create content in my d2l orgUnit but I keep getting 404 Page not found back. I am calling this from the Android emulator. I've successfully created a module as well as a topic link using the POST APIs. I did look at this post 404 Posting Content to Desire2Learn which helped me get the module and link working, but I just can't get the uploading a file as a topic to work. I suspect it may be the URL as I wasn't sure what to put, so I put a relative path I created in the org unit. The post 404 Posting Content to Desire2Learn mentions to use "valid location URL to within the org unit's existing content space". I also tried the /content/enforced/... folder as URL to no avail. I'm not sure if this is the issue, or a red herring...
Here is my code:
String body = "--xxBoundaryxx " +
"Content-Type: application/json " +
"{" +
"\"Title\": \"Testing an upload\"," +
"\"ShortTitle\": \"test\"," +
"\"Type\": 1," +
"\"TopicType\": 1," +
"\"URL\": \"/test/\"," +
"\"StartDate\": null," +
"\"EndDate\": null," +
"\"IsHidden\": false," +
"\"IsLocked\": false" +
" } " +
"--xxBoundaryxx " +
"Content-Disposition: form-data; name=\"file 0\"; filename=\"test.txt\" " +
"Content-Type: text/plain " +
"This is my sample file to try it out.";
URI uri = userContext.createAuthenticatedUri("/d2l/api/le/1.1/{OrgID}/content/modules/{ModuleID}/structure/", "Post");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(uri);
post.addHeader("Content-Type", "multipart/mixed; boundary=xxBoundaryxx");
post.setEntity(new StringEntity(body));
HttpResponse response = httpClient.execute(post);
Log.i(TAG, "Statusline: " + response.getStatusLine());
Here is the resulting body (I put \r\n for line breaks as well, but it didn't help).
--xxBoundaryxx
Content-Type: application/json
{
"Title": "Testing an upload",
"ShortTitle": "test",
"Type": 1,
"TopicType": 1,
"URL": "/test/",
"StartDate": null,
"EndDate": null,
"IsHidden": false,
"IsLocked": false
}
--xxBoundaryxx
Content-Disposition: form-data; name="file 0"; filename="test.txt"
Content-Type: text/plain
This is my sample file to try it out.
what is going on? getStatusLine always returns 404 error... I know it is not a permission issue since I can create modules and link topics successfully using very similar code. Any guidance greatly appreciated.
You almost certainly need a terminating boundary on your POST body (--xxBoundaryxx--). For the Url property in the JSON block you send: you can send an Url that's not relative (as in the example in the docs); it also seems you can send just a file name (relative name) and the upload process puts the file in the root of the course's content area. I would fully expect that (a) if you don't have an absolute URL, it would use the course's root folder as the base part of the path, and (b) the upload API action will not create directories for you, but I haven't comprehensive testing around how the Url property gets handled.
I've tested this API action on our test servers, and it works (with a fully specified Url and just a file name for the Url). I've also updated the Valence docs to include a concrete example of the course content file topic upload packet: hope these two things help you out.

Resources