Tuesday, 15 May 2012

php - Retrieving Angularjs Http Post data -


I am new to angularjs, I am using a user name and user name and password ), But the strange thing is that I'm unable to get data using server $ _POST, instead I can retrieve it via $ _GET From I have other forms like CORS There is no mistake in checking the pains and there is no mistake. A guide would be appreciated thanks.

Here's my angular factory method:

  app.factory ("loginfact", function ($ http) {this.user = { IsAuthenticated: false, name: "", token: ""} this.makeLoginRequest = function (user, pass) {var req = {method: 'post', url: 'http: // localhost / login / authenticate php', Header: {'content-type': "multipart / form-data"}, parameters: {username: user, password: pass}} $ http (req) .vivet (data) {console.log ("success : "+ Data)}). Error (function (data) {console.log (" error: "+ data)})}} return {makeLoginRequest: this.makeLoginRequest}});  

Here is my server part:

  & lt; Php header ('accept-charset: UTF-8'); Header ('Connection: Keep-alive'); Header ('content-type: multipart / form-data,'); Header ('access-control-permission-origin: *'); Header ('access-control-app-methods: GET, post'); Header ('access-control-app-headers: approved, content-type'); Header ('Access-Control-Request-Header: X-Requested-Accept, Content-Type'); {{($ _ POST ["user name"] == "test") & amp; Amp; ($ _POST ["password"] == "test")) {echo "{\" id \ ": \" 700 \ ", \" User \ ": {\" uid \ ": \" 123456 \ ", \ "Role \": \ "admin \", \ "name \": \ "waqar \"}} "; Return; } Else {echo "phase1: invalid user name / password"; Return; }} Hold (exception $ e) {echo $ e-> GetMessage (); } Try {$ Request_body = file_get_contents ('php: // input'); $ Data = json_decode ($ request_body); If ($ data-> username == "test" & amp; amp; $ amp; data-> password == "test") {echo "{\" id \ ": \" 700 \ " , \ "User \": {\ "Uid \": \ "123456 \", \ "role \": \ "admin \", \ "name \": \ "void \"}}; return;} Else {Echo "step 2: invalid user name / password"; return;}} hold (exception $ e) {echo $ e-> getMessage (); return;}? & Gt;   < / Div> 

You can object to parameter data by sending data to query parameter (URL - ? Key1 = value1 & amp; key2 = value2 ) in the header

You instead of data object:

  var req = {method: 'post', url: 'http: //localhost/login/authenticate.php ', header: {content - type: "multipart / form-data"}, data: {username: user, password: pass}}  

Check for more information.

If I understand correctly, in the comments you are asking: Why the parameters were kept in the body of the request instead of URL?

You can send them to the URL, but you have some drawbacks:

  • The encoding is better in the body than the URL
  • You do
  • It is usually limited by the length of the URL (the system varies but about 2000 characters)
  • It is easy to deceive the URL
  • The system usually saves the URL of their log so that you take the risk of exposing your client's accounts if a law (Note that they will be saved in plain text, even if you encrypt them in the database)
  • Considering the last point, the country is illegal to log sensitive data in some You can.

No comments:

Post a Comment