简体   繁体   中英

how to get request HTTP headers in soaplib views file?

i have soaplib for webservice as soap [server], all request route and response as xml by url well.but i can't fetch request http headers, How can i get request HTTP headers for rendering view some method of class ?

like this method :

def redirect_http(self,request):
    return render(request, 'ask/redirect.html', {
        ''' 'question': question,
        'error_message': "You didn't select a choice.", '''
    })

Code Project :

soap.py

'''
documentation in http://soaplib.github.com/soaplib/2_0/
'''
import base64
import soaplib
from soaplib.core import Application
from soaplib.core.model import primitive as soap_types
from soaplib.core.service import DefinitionBase
from soaplib.core.service import rpc as soapmethod
from soaplib.core.server import wsgi
from soaplib.core.model.clazz import ClassModel
from soaplib.core.model.clazz import Array

from django.http import HttpResponse

# the class with actual web methods

# the class which acts as a wrapper between soaplib WSGI functionality and Django
class DjangoSoapApp(wsgi.Application):
    def __call__(self, request):
        # wrap the soaplib response into a Django response object
        django_response = HttpResponse()
        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            django_response.status_code = int(status)
            for header, value in headers:
                django_response[header] = value
        response = super(DjangoSoapApp, self).__call__(request.META, start_response)
        django_response.content = '\n'.join(response)
        return django_response

class SoapView(DefinitionBase):
    @classmethod
    def as_view(cls):
        soap_application = Application([cls], __name__)
        return DjangoSoapApp(soap_application)


# the view to use in urls.py
#my_soap_service = DjangoSoapApp([MySOAPService], __name__)

views.py

from soap import SoapView
from soap import soapmethod
from soap import soap_types, Array
class MySoapService(SoapView):
    __tns__ = '[url]http://localhost:8989/api/soap/verify.wsdl[/url]'
    @soapmethod(soap_types.String, soap_types.Integer, returns=soap_types.String)
    def request_verify(self, q, id, uri):
        #Some Code
        return 'some return'
my_soap_service = MySoapService.as_view()

urls.py

from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView
import views

# Main URL Patterns
urlpatterns = [
  url(r'^verify', views.my_soap_service),
  url(r'^verify.wsdl', views.my_soap_service),
]

解决的问题:更改方法请求(用于生成html并获取http头,最遵守协议的HTTP和结构),因此要请求和响应html内容应发送http请求并获取所有头

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM