Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set request headers for REST authentication #28

Closed
kabasakalis opened this issue Apr 20, 2013 · 3 comments
Closed

Set request headers for REST authentication #28

kabasakalis opened this issue Apr 20, 2013 · 3 comments

Comments

@kabasakalis
Copy link

Hi,great directive!.I am working on an angular app featuring basic REST CRUD operations.Problem is,my create action features an image upload(along with other text fields),and the REST API authenticates the requests with custom headers.With ajax this is no problem,you can set custom headers on the client,but with iframe technique that your directive uses-this is a problem.Do you have any idea on how to solve this?Thanks in advance!

@twilson63
Copy link
Owner

Since its actually doing a form POST, I think it would be pretty hard to
set custom headers, but you can do one of the following:

If you don't have to support ie browsers less than 10 then you should use
FormData api, it allows you to use xhr2 to submit files via ajax.

https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/FormData

If you do have to worry about supporting IE 8 and IE 9, then you could
submit everything but your files via an ajax post and then submit just your
files via the iframe post, you should be able to execute both so that the
user only has to click once. Let me know if this answers your question.

Thanks for the feedback

Tom

On Sat, Apr 20, 2013 at 4:01 PM, Spiros Kabasakalis <
notifications@github.com> wrote:

Hi,great directive!.I am working on an angular app featuring basic REST
CRUD operations.Problem is,my create action features an image upload(along
with other text fields),and the REST API authenticates the requests with
custom headers.With ajax this is no problem,you can set custom headers on
the client,but with iframe technique that your directive uses-this is a
problem.Do you have any idea on how to solve this?Thanks in advance!


Reply to this email directly or view it on GitHubhttps://github.com//issues/28
.

Tom Wilson
Jack Russell Software Company Division of CareKinesis
494 Wando Park Blvd
Mount Pleasant, SC 29464
Phone: 843-881-2171
Email: tom@jackhq.com
Web: http://www.jackhq.com
Calendar:
http://www.google.com/calendar/embed?src=tom%40jackrussellsoftware.com&ctz=America/New_Yorkhttp://www.jackhq.com/calendar

This e-mail may contain information that is confidential, privileged or
otherwise protected from disclosure by the Health Insurance Portability and
Accountability Act (HIPAA) and other state and federal laws. This
information is intended only for the individual names above. Any review,
use disclosure or dissemination of this material is strictly prohibited.
If you receive this information in error, please notify CareKinesis
immediately at 888-974-2763 and delete the original at once.

@kabasakalis
Copy link
Author

Thanks Tom,I used FormData,I could care less for old IEs,this is a demo for developers anyway (Angular with PHP backend -Yii framework).I ended up using this

    $scope.create=function(){
       var  form = $('#cform');
        var formdata = false;
            if (window.FormData){
                formdata = new FormData(form[0]);
            }
      var   method='POST';
     var formAction ="http://yii.gr/lab/api/resttest";
        $http( {
            data:formdata,
            url:formAction,
            method:method,
          headers: { 'Content-Type': false,                                     
                         'X_REST_PASSWORD':'PASSWORD',
                         'X_REST_USERNAME':'kabasakalis@gmail.com' },
         transformRequest: function(data) { return data; }
        }).success(function(response, status, headers, config) {
            // this callback will be called asynchronously
            // when the response is available
                  //stuff to do with response
          }).
          error(function(data, status, headers, config) {
 //stuff to do on error
          });

    };

@twilson63
Copy link
Owner

Awesome!!

Thx

Tom

Sent from my iPhone

On Apr 27, 2013, at 3:35 PM, Spiros Kabasakalis notifications@github.com
wrote:

Thanks Tom,I used FormData,I could care less for old IEs,this is a demo for
developers anyway (Angular with PHP backend -Yii framework).I ended up
using this

$scope.create=function(){
   var  form = $('#cform');
    var formdata = false;
        if (window.FormData){
            formdata = new FormData(form[0]);
        }
  var   method='POST';
 var formAction ="http://yii.gr/lab/api/resttest";
    $http( {
        data:formdata,
        url:formAction,
        method:method,
      headers: { 'Content-Type': false,
                     'X_REST_PASSWORD':'PASSWORD',
                     'X_REST_USERNAME':'kabasakalis@gmail.com' },
     transformRequest: function(data) { return data; }
    }).success(function(response, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
              //stuff to do with response
      }).
      error(function(data, status, headers, config) {

//stuff to do on error
});

};


Reply to this email directly or view it on
GitHubhttps://github.com//issues/28#issuecomment-17121944
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants