我已经getJSON脱离了我对最简单的例子的呼吁,试图弄清楚为什么它不起作用但是我没有想法.我目前有:
public JsonResult MyAction()
{
return Json(new { status = "OK" });
}
$.getJSON('MyController/MyAction', function(result) { alert('worked'); });
Run Code Online (Sandbox Code Playgroud)
该操作被调用,但警报不会被触发并查看Chrome开发人员工具我看到返回状态500错误代码.什么可能导致这个?我该怎么调试呢?
我正在尝试在html5上传文件中进行一些测试,这里是简单的html代码:
var fileInput=document.getElementById("the-file")
fileInput.addEventListener('change',function(e){
var file=e.target.files[0]
var xhr=new XMLHttpRequest()
xhr.open('post','upload/handlecode',true)
xhr.send(file)
}
我
python -m SimpleHTTPServer
用来测试这一节的问题是我不知道如何编写handlecode文件来处理http请求,
该handlecode文件只保存文件上传floder,没有更复杂的任务
虽然我不知道以这种方式测试是否正确
有人可以提供一些提示或给我正确的测试方法,非常感谢你们!
我得到了一个"普通"的ascx-Page,其中包含HTML-Parts以及后面的代码.这些元素都应该在正常条件下显示(工作).
现在我希望能够设置一个request-parameter,这会导致页面zu以不同方式呈现.然后,它发送该页面上的信息,不是人类可读的,而是机器:
string jsonProperty = Request["JSonProperty"];
if (!string.IsNullOrEmpty(jsonProperty))
{
Response.Clear();
Response.Write(RenderJSon());
// Response.Close();
return;
Run Code Online (Sandbox Code Playgroud)
此代码位于Page_PreRender内.现在我的问题是:字符串被正确发送到浏览器,但之后仍然呈现"标准"html内容.
当我删除"Response.Close();" 评论我收到"ERR_INVALID_RESPONSE"
有什么线索如何在不创建额外页面的情况下解决这个问题?
好吧,我无法理解为什么字符串比较不起作用
protected String doInBackground(String... args)
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_login);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
InputStream is = entity.getContent();
String returnState = new String();
returnState = convertStreamToString(is);
Log.d("retunState ", returnState); // returning desired string
//if (returnState=="user") // this is not working, however returnState = user
// OR
//if (returnState.equals("user"))
// OR
if (returnState.equalsIgnoreCase("user")) // this is not working also
{
Intent i = new Intent(Main.this, SecondPage.class);
startActivity(i);
finish();
} …Run Code Online (Sandbox Code Playgroud) 我的所有控制器都扩展了以下抽象类:
public abstract class AbstractController {
public HttpServletRequest request;
public HttpServletResponse response;
public ModelMap model;
}
Run Code Online (Sandbox Code Playgroud)
而且,我实现了以下拦截器:
public class HttpRequestInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
if (handler instanceof AbstractController) {
AbstractController controller = (AbstractController) handler;
controller.request = request;
controller.response = response;
controller.model = new ModelMap();
}
return true;
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
if (handler instanceof AbstractController && modelAndView != null) {
AbstractController controller …Run Code Online (Sandbox Code Playgroud) 我正在运行一个Apache Web服务器.我想在从我的Web服务器发出的所有响应头中添加"X-Content-Type-Options:nosniff".我怎样才能做到这一点?是否可以对apache配置文件进行更改以实现此目的?
我正在使用ASP.NET WebAPI2.这是我的代码:
[HttpPost]
public HttpResponseMessage SaveNewPdf(HttpRequestMessage req)
{
var json = req.Content.ReadAsStringAsync().Result;
NewFile newFile = JsonConvert.DeserializeObject<NewFile>(json);
string error = string.Empty;
// check all the foreign key values to ensure they are valid
var isArticleCategoryValid = HelperClasses.ForeignKeyChecks.IsArticleCategoryValid(newFile.ArticleCategory);
var isDocumentTypeValid = HelperClasses.ForeignKeyChecks.IsDocumentTypeValid(newFile.DocumentType);
var isActionPublisherValid = HelperClasses.ForeignKeyChecks.IsActionPublisherValid(newFile.ActionPublisher);
var isRuleComplianceValid = HelperClasses.ForeignKeyChecks.IsRuleComplianceValid(newFile.RuleCompliance);
if (!isArticleCategoryValid)
{
error = "articleCategory in the JSON is not a valid Article Category";
return new HttpResponseException();
}
}
Run Code Online (Sandbox Code Playgroud)
我想做一些如上所示的事情 - 返回一个表示错误的异常.我知道我可以返回一个HttpResponseMessage,其状态代码是我想要的,但我想返回一个Exception.我知道HttpResponseException,但这需要一个HttpResponseMessage,所以我回到原点.可能会返回异常吗?
func main() {
http.HandleFunc("/", foo)
http.ListenAndServe(":3000", nil)
}
func foo(w http.ResponseWriter, r *http.Request) {
s:= "name"
fp := path.Join("templates", "index.html")
tmpl, err := template.ParseFiles(fp)
if err != nil {
panic(err)
}
if err := tmpl.Execute(w, s); err != nil {
panic(err)
}
fmt.Println("successfull Operation!!")
}
Run Code Online (Sandbox Code Playgroud)
此代码显示2"successl Operation !!" 但是当我添加/home(http.HandleFunc("/home", foo))时,它没有.我想知道为什么它显示"成功操作!!" 两次.先感谢您.
我的python版本是3.4,我的tornado版本是4.3。我的代码是这样的:
import tornado.ioloop
import tornado.web
import tornado.httputil
import tornado.httpserver
class MainHandler(tornado.web.RequestHandler):
def get(self):
body = 'foobar'*10
self.set_header('Transfer-Encoding', 'chunked')
self.write(body)
self.flush()
self.finish()
app = tornado.web.Application([
(r'/chunked', MainHandler),
])
if __name__ == "__main__":
app.listen(8080)
tornado.ioloop.IOLoop.current().start()
Run Code Online (Sandbox Code Playgroud)
这根本行不通,客户端只是等待块结束。如何在使用 Tornado 服务器时正确生成分块响应?
我正在尝试生成一个文本文件并从模板中的链接下载它,但单击链接后没有任何反应.
这是我在模板中的链接.
<a href="{% url 'download' %}"><h2>{{ fname }} {{ lname }}</h2></a>
Run Code Online (Sandbox Code Playgroud)
这是我的看法
def report_generate(request):
f = open("test.txt", "w+")
for i in range(10):
f.write("This is line %d\r\n" % (i + 1))
response = HttpResponse(f.read(), content_type='text/plain')
filename = "guru99.txt"
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
return response
Run Code Online (Sandbox Code Playgroud)
这是我的urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', qrview.index),
path('forms/new_profile', formsview.profile_create, name="aaa"), # test
path('forms/new_course', formsview.course_create, name="ddd"), # test
path('forms/edit_course', formsview.course_edit, name="edit_course"),
path('report/', reportview.report, name="report"),
path('report/', reportview.report_generate, name="download"),
#path('admin/', admin.site.urls),
#path('admin/', admin.site.urls),
Run Code Online (Sandbox Code Playgroud)
]
httpresponse ×10
python ×3
http ×2
ajax ×1
android ×1
apache ×1
asp.net ×1
asp.net-mvc ×1
c# ×1
chunked ×1
django ×1
download ×1
exception ×1
go ×1
html5 ×1
http-headers ×1
httprequest ×1
interceptor ×1
java ×1
javascript ×1
jquery ×1
mime-types ×1
spring-mvc ×1
string ×1
testing ×1
tornado ×1