2016-08-09 4 views
0

Ich habe eine native App reagieren, die nodejs und Express für Backend verwendet haben, Cors aktiviert und die auf Android laufen, aber wenn ich begann, die App für IOS zu portieren und es im Simulator iphone laufen 6, es läuft gut, aber wenn es darum geht, eine API dafür zu treffen, benutzte ich superagent geben Sie mir diesen Fehler.Fehler bei der Verwendung von Superagent in reagieren native iOS-App

Error: Request has been terminated 
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc. 
    at Request.crossDomainError (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:80241:9) 
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:80311:13) 
    at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:10000:15) 
    at XMLHttpRequest.setReadyState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:26063:6) 
    at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25917:6) 
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:26011:52 
    at RCTDeviceEventEmitter.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:9233:23) 
    at MessageQueue.__callFunction (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7213:34) 
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7104:8 
    at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7050:1) 

dies ist, wie Superagent i

verwenden
const request = require('superagent'); 

const req = request[options.method.toLowerCase()](options.uri) 
     .set(merge({}, options.headers, options.json ? {'Content-Type': 'application/json'} : {})) 
     .query(options.qs ? options.qs : {}) 
     .send(options.json || options.form || options.formData) 
     ; 
     const requestId = {}; 

     api.activeRequests.add(requestId); 
     return new Promise((resolve, reject) => { 
     req.end((err, res) => { 
      console.log({err, res}); 
      api.activeRequests.delete(requestId); 
      if (err || !res.ok) { 
      console.log(res); 
      const error = res ? (res.body ? res.body : res) : err; 
      reject(error); 
      } else { 
      resolve(res.body); 
      } 
     }); 
     }); 

Brauchen Sie Hilfe!

+0

Bitte erstellen Sie eine [MVCE] (http://StackOverflow.com/Help/Mcve), ansonsten ist es unwahrscheinlich, dass wir Ihnen mit den von Ihnen geposteten Informationen helfen können. – Harald

+0

Welche genauen Informationen benötigen Sie? – Deepak

+0

Setzen Sie sich in die Position von jemandem, der versucht, Ihre Frage zu beantworten. Je mehr Details Sie ihnen zur Verfügung stellen können, desto einfacher ist es für sie, Ihnen zu helfen. Zum Beispiel haben Sie ein kleines Stück Code hinzugefügt, aber kompiliert es alleine, ist es MVCE? Sie haben wichtige Details aus den von Ihnen verwendeten Softwareteilen weggelassen, welche Versionen, welche Plattformen? ... Details sind wichtig. – Harald

Antwort

0

Es war wegen https Anfrage nicht http gepostet werden. So ab jetzt, da ich im Entwicklermodus bin, erlaubt http zu meiner bestimmten Domäne.

Verwandte Themen